Write this Visual Basic code in Powerbuilder [closed] - powerbuilder

How to write the following VB code in PB?
Dim fso As New Scripting.FileSystemObject()
For Each str As Scripting.Drive In fso.Drives
If str.IsReady Then
TextBox1.Text += "Volume Name : " & str.VolumeName
End If
Next

Try this :
OLEObject ole_wsh
string ls_values, ls_message
ole_wsh = CREATE OLEObject
ole_wsh.ConnectToNewObject("MSScriptControl.ScriptControl")
ole_wsh.Language = "vbscript"
ole_wsh.AddCode('Function retDrives()~r~n' &
+ 'Set fso = CreateObject("Scripting.fileSystemObject")~r~n' &
+ 'drivesVolume = ""~r~n' &
+ 'For Each str In fso.Drives ~r~n' &
+ ' If str.IsReady Then ~r~n' &
+ ' drivesVolume = drivesVolume + "[" + str.VolumeName + "]" ~r~n' &
+ ' End If ~r~n' &
+ 'Next~r~n' &
+ 'retDrives=drivesVolume~r~n' &
+ 'End Function')
ls_values = ole_wsh.Eval("retDrives")
ole_wsh.DisconnectObject()
DESTROY ole_wsh
ls_message = "VOLUMES(s): " + ls_values
MessageBox("DRIVES",ls_message)

You will need to declare and use a Windows API for this type of functionality. Probably GetLogicalDrives or similar. You may wish to take a look at the Filesys application by Roland Smith of Topwiz Software (www.topwizprogramming.com under Free Code). This sample application has many system information / manipulation methods coded.

Related

How can I write a regular expression for this in android?

I am having a string(number) with special characters. I want to search for a sub-string(comprising of digits only) & also I want to detect the starting index & ending index of matching sub-string in the string.
For example: main string: (+91)-1231212 1231
Sub-string to search: 1212
Currently I am using the following code to do this but in place of 1212,it searched for 12312. For other cases, it works fine.
String sss0 = "1212";
String sss1 = "(+91)-1231212 1231";
sss0 = sss0.replaceAll("[^\\d]","");
System.out.println("*************************"+sss0);
String ptn = "" + sss0.charAt(0);
for(int jj=0; jj<sss0.length()-1; jj++){
ptn += "[^" + sss0.charAt(jj) + sss0.charAt(jj+1) + "]*?" + sss0.charAt(jj+1);
}
System.out.println("ptn: " + ptn);
Pattern p300 = Pattern.compile(ptn);
Matcher m300 = p300.matcher(sss1);
if(m300.find()){
System.out.println("start, stop: " + m300.start() + "," + (m300.end()-1 ));
System.out.println("substring: " + sss1.substring(m300.start(), m300.end()));
}
Please help me. Thanks in advance.
Try this :
int start = sss1.indexOf(sss0);
if(start != -1) {
System.out.println("Start : " + start);
System.out.println("End : " + start.length()); //maybe add +1 here depending on what you mean by end index.
}
You can also put this in a loop to find all occurences of the substring.
pseudocode:
pattern = ""
foreach char c in sss0:
pattern += c + "[^0-9]*"
found_substring = match(pattern, sss1)
the idea being to intersperse the literal characters you're looking for with the pattern that you're willing to skip over.

node-red split, reorder and join an output string

I am trying to reorder an output string in node-red like the following example:
Output:
msg.payload: rgb(152,11,100)
I want to have it like this:
mg.payload: rgb(11,100,152)
I tried with split node using , string, then I got three outputs, but I could not join them again with the order I want
The easiest way to do this is probably just with a regex in a function node.
var re = /rgb\((\d+),(\d+),(\d+)\)/;
var match = re.exec(msg.payload);
msg.payload= "rbg(" + match[2] + "," + match[3] + "," + match[1] + ")";
return msg
I got another answer which also work (thanks to z1rconium)
use a function node:
input = msg.payload
str = input.substr(4,input.indexOf(")")-4)
out = str.split(",");
// creates an array you can use;
// out[0] = 152
// out[1] = 11
// out[2] = 100
return {payload:"rgb("+out[1]+","+out[2]+","+out[0]+")"}
//msg.payload : string[14]
//"rgb(11,100,152)"
Alternative code to use inside a function node. It uses ES6 capabilities:
let pay = msg.payload.slice(4, -1).split(",");
let [r,g,b] = [...pay];
msg.payload = `rgb(${g},${b},${r})`;
return msg;

Ignoring blank email address input field Google Apps Script

I have an HTML form which contains email addresses from various suppliers. I am creating a kind of mail merge function so I can send all the contacts a personalised email when the form is submitted. Here is my .gs file:
function sendEmail(form) {
const sSheet = SpreadsheetApp.getActiveSpreadsheet();
const file = DriveApp.getFileById(sSheet.getId());
const documentUrl = file.getUrl();
/* var toEmail = form.toAddress;
var ccEmail = form.ccAddress;
var fromEmail = "****#*****.com";
var subject = form.subject;
var message = form.message; */
var toEmail = "";
var fromEmail = "****#*****.com";
var message = "";
var hotelAddresses = [
form.toAddress1,
form.toAddress2,
form.toAddress3,
form.toAddress4,
form.toAddress5,
form.toAddress6,
form.toAddress7,
form.toAddress8,
form.toAddress9,
form.toAddress10,
form.toAddress11,
form.toAddress12,
form.toAddress13,
form.toAddress14,
form.toAddress15,
form.toAddress16,
form.toAddress17,
form.toAddress18,
form.toAddress19,
form.toAddress20,
form.toAddress21,
form.toAddress22,
form.toAddress23,
form.toAddress24,
form.toAddress25,
form.toAddress26,
form.toAddress27,
form.toAddress28,
form.toAddress29,
form.toAddress30,
form.toAddress31,
form.toAddress32,
form.toAddress33,
];
var contactNames = [
form.contactName1,
form.contactName2,
form.contactName3,
form.contactName4,
form.contactName5,
form.contactName6,
form.contactName7,
form.contactName8,
form.contactName9,
form.contactName10,
form.contactName11,
form.contactName12,
form.contactName13,
form.contactName14,
form.contactName15,
form.contactName16,
form.contactName17,
form.contactName18,
form.contactName19,
form.contactName20,
form.contactName21,
form.contactName22,
form.contactName23,
form.contactName24,
form.contactName25,
form.contactName26,
form.contactName27,
form.contactName28,
form.contactName29,
form.contactName30,
form.contactName31,
form.contactName32,
form.contactName33,
];
var days = [
form.day1,
form.day2,
form.day3,
form.day4,
form.day5,
form.day6,
form.day7,
form.day8,
form.day9,
form.day10,
form.day11,
form.day12,
form.day13,
form.day14,
form.day15,
form.day16,
form.day17,
form.day18,
form.day19,
form.day20,
form.day21,
form.day22,
form.day23,
form.day24,
form.day25,
form.day26,
form.day27,
form.day28,
form.day29,
form.day30,
form.day31,
form.day32,
form.day33,
];
var dates = [
form.date1,
form.date2,
form.date3,
form.date4,
form.date5,
form.date6,
form.date7,
form.date8,
form.date9,
form.date10,
form.date11,
form.date12,
form.date13,
form.date14,
form.date15,
form.date16,
form.date17,
form.date18,
form.date19,
form.date20,
form.date21,
form.date22,
form.date23,
form.date24,
form.date25,
form.date26,
form.date27,
form.date28,
form.date29,
form.date30,
form.date31,
form.date32,
form.date33,
];
var times = [
form.time1,
form.time2,
form.time3,
form.time4,
form.time5,
form.time6,
form.time7,
form.time8,
form.time9,
form.time10,
form.time11,
form.time12,
form.time13,
form.time14,
form.time15,
form.time16,
form.time17,
form.time18,
form.time19,
form.time20,
form.time21,
form.time22,
form.time23,
form.time24,
form.time25,
form.time26,
form.time27,
form.time28,
form.time29,
form.time30,
form.time31,
form.time32,
form.time33,
];
var additionalInfo = [
form.additional1,
form.additional2,
form.additional3,
form.additional4,
form.additional5,
form.additional6,
form.additional7,
form.additional8,
form.additional9,
form.additional10,
form.additional11,
form.additional12,
form.additional3,
form.additional14,
form.additional15,
form.additional16,
form.additional17,
form.additional18,
form.additional19,
form.additional20,
form.additional21,
form.additional22,
form.additional23,
form.additional24,
form.additional25,
form.additional26,
form.additional27,
form.additional28,
form.additional29,
form.additional30,
form.additional31,
form.additional32,
form.additional33,
];
for(var i = 0; i<times.length; i++){
var subject = "Meeting - " + days[i] + ", " + dates[i] + " at " + times[i];
toEmail = hotelAddresses[i];
message = "Dear " + contactNames[i] + ","
+"<br><br>"+
"Please confirm the meeting on " + days[i] + " " + dates[i] + " at " + times[i] + "." + "<br>" + "<br>" +
additionalInfo[i] +
" If you could kindly let me know if you are able to confirm that would be great." + "<br>" + "<br>" +
"Many thanks and I look forward to hearing from you soon." + "<br>" + "<br>" +
"Yours sincerely," + "<br>" + "<br>" +
form.yourName + "<br>" + "<br>"
+ "<em><b>" + form.yourPosition + "</b></em> <br><br>" +
"<span style='color:#0e216d'><b> Company name. </b>" + "<br>" +
GmailApp.sendEmail(
toEmail, // recipient
subject, // subject
'test', { // body
htmlBody: message // advanced options
}
);
}
}
It works fine except that sometimes the input fields for email will be blank, in which case I need the script to ignore that supplier and continue to run. At the moment it is obviously hitting the empty input and stopping the execution.
I presume I need a conditional statement of sorts... something along the lines of if(hotelAddresses[i] != null) {}
But I cannot work out where to insert this...
Additional: 31 Aug 18
For the HTML I have a series of objects (33 in total) that are all set up like this:
<input type="checkbox" id="check1" class="check" checked>
<input type="text" id="name1" class="contactNameInput" name="toAddress1">
<input type="text" id="contactName1" class="contactNameInput mailName" name="contactName1">
<input type="text" id="time1" class="contactNameInput hidden mailTime" name="time1">
<input type="text" id="day1" class="contactNameInput hidden mailDay" name="day1">
<input type="text" id="date1" class="contactNameInput hidden mailDate" name="date1">
<textarea class="additional contactNameInput" id="additional1" name="additional1" placeholder="Additional requests..."></textarea>
<div class="preview1"></div>
You want to separate the cases with and without hotelAddresses[i] using a script like if(hotelAddresses[i] != null) {}. When my understanding is correct, how about this modification?
Modification points:
Do you want to add after "<span style='color:#0e216d'><b> Company name. </b>" + "<br>" +? In the current script, it's "<span style='color:#0e216d'><b> Company name. </b>" + "<br>" + GmailApp.sendEmail(...). If you want to add more strings, please put them. If you don't want to add, please remove the last +.
I think that the script of if(hotelAddresses[i] != null) {} can be used in the for loop.
The script which reflected above is as follows.
Modified script:
In this modified script, the script of for loop was modified.
for(var i = 0; i<times.length; i++) {
var toEmail = hotelAddresses[i];
if (toEmail) {
var subject = "subject";
var message = "messages";
GmailApp.sendEmail(toEmail, subject, 'test', {htmlBody: message});
} else {
// do something
}
}
Note:
In this modified script, subject and message are replaced by "subject" and "messages", respectively. So please modify them for your situation.
If you want to do something when hotelAddresses[i] is null, please modify // do something.
If you don't want to do something when hotelAddresses[i] is null, please remove else {}.
If I misunderstand your question, please tell me. I would like to modify it.

asp email form - trying to insert leading space

I used this script on my website to collect enquiry form information from visitors. One of my clients reports that when he receives the email that's generated, Outlook is manipulating the line:
email=myclient#myclientsdomain.com
...to include the prefix "email=" as if that's part of the email! (Silly Outlook!)
I need to alter my code so a leading space is inserted immediately before the email address so it looks more like this:
email= myclient#clientsdomain.com
That way, when my client clicks on the email to reply to the user, the correct email is used (the one without the prefix attached to the front of the email!)
In summary Outlook is including the prefix when it creates an email link because of the absence of any space between the email and the prefix.
I'm not much of a coder and extensive searching has failed me. I tried lots of suggestions but my form seems to either fail or no fix happens.
<!--START CODE FOR SENDFORM.ASP -->
<%# LANGUAGE="VBScript" %>
<%
Dim sFormTitle, sFormSender, sFormSubject, sFormDestination
'============================================
' You only need to change the details below!
'============================================
sFormTitle = "enquiries"
sFormSender = “myemail#mydomain.com"
sFormDomain = “mydomain.com"
sFormSubject = "Enquiry From Website."
sFormDestination = “me#mydomain.com"
'sFormDestination = “mail#mydomain.com"
'============================================
' And that's it!
'============================================
Dim sRawForm, aFormArray, sElement, sFormData
sRawForm = request.form
aFormArray = Split(sRawForm, "&")
for i = 0 to UBOUND(aFormArray)
sElement = Unescape(aFormArray(i))
sElement = Replace( sElement, "+", " " )
sFormData = sFormData & sElement & vbCrLf
next
%>
<%
Dim sRecipients, sBody, sSubject
sRecipients = Request.Form( sFormDestination )
sBody = sFormData
sSubject = sFormSubject
dim msg
set msg = Server.CreateOBject( "JMail.SMTPMail" )
msg.Logging = true
msg.silent = true
msg.Sender = sFormSender
msg.SenderName = sFormTitle
msg.AddRecipient sFormDestination
msg.Subject = sSubject
msg.Body = sBody
msg.ServerAddress = "IP GOES HERE - REMOVED IT FOR THIS POSTING"
if not msg.Execute then
Response.redirect "http://mydomain.co.uk/sorry.html"
else
Response.redirect "http://mydomain.co.uk/thanks.html"
end if
%>
<!--END CODE FOR SENDFORM.ASP -->
EDIT BELOW IN RESPONSE TO LANKYMART'S SUGGESTIONS:
Lankymart - Outlooks sees the text string email=myclient#myclientsdomain.com contains an # symbol in the middle and interprets the whole thing to be the email address - as such it makes the whole thing a clickable email link. If my form could generate a non breaking space, Outlook would still make that an email link but without the unwanted prefix included.
I can't use &nbsp - I don't know how to automatically insert it using the script (this is what I'm asking). Perhaps you meant on my html form page - this won't "carry through" to the email that's batched up and sent.
The square brackets have the same issue - if the asp form could somehow automatically insert these for me, the email will arrive and Outlook might display it correctly - getting my form to do this is the part I need to know. (I feel a leading space might be better as this will definitely work)
Any other ideas?
It's simple just use Replace() to identify the equals and add the &nbsp (Non-breaking space).
sRawForm = Request.Form
aFormArray = Split(sRawForm, "&")
For i = 0 To UBound(aFormArray)
sElement = Unescape(aFormArray(i))
sElement = Replace(sElement, "=", " =")
sElement = Replace(sElement, "+", " " )
sFormData = sFormData & sElement & vbCrLf
Next
Or to try the < > method using Replace();
sRawForm = Request.Form
aFormArray = Split(sRawForm, "&")
For i = 0 To UBound(aFormArray)
sElement = Unescape(aFormArray(i))
sElement = Replace(sElement, "=", "=<") & ">"
sElement = Replace(sElement, "+", " " )
sFormData = sFormData & sElement & vbCrLf
Next
If you just want the form values without outputting name=value just iterate through the Request.Form collection like;
Dim element
For Each element In Request.Form
sFormData = sFormData & element.Value & vbCrLf
Next
This would be my preferred method for iterating through the Request.Form collection, if you want the key value pair approach name=value you can still do that like this;
Dim element
For Each element In Request.Form
'Both and < > methods shown but < > preferred.
'sFormData = sFormData & element.Name & "= " & element.Value & vbCrLf
sFormData = sFormData & element.Name
'Only add < > if it's the email element.
If element.Name = "email" Then
sFormData = sFormData & "=<" & element.Value & ">" & vbCrLf
Else
sFormData = sFormData & "=" & element.Value & vbCrLf
End If
Next
Update:
In reply to the question in the comments the above code should replace;
sRawForm = request.form
aFormArray = Split(sRawForm, "&")
for i = 0 to UBOUND(aFormArray)
sElement = Unescape(aFormArray(i))
sElement = Replace( sElement, "+", " " )
sFormData = sFormData & sElement & vbCrLf
next
Because your iterating through the Request.Form collection instead of using Split() to build an Array and loop through that, you no longer have to do all the string clean-up, this is one of the benefits of using the For Each approach.

code opening IE but need safari and Firefox

How can I get this code to work with Safari or Firefox?
Public Function getGoogDistanceTime(startAddr As String, startCity As String, _
startState As String, startZip As String, endAddr As String, _
endCity As String, endState As String, endZip As String) As String
Dim sURL As String
Dim BodyTxt As String
Dim apan As String
Dim oXH As Object
sURL = "http://maps.google.com/maps?f=d&source=s_d&saddr="
sURL = sURL & Replace(startAddr, " ", "+") & ",+" & Replace(startCity, " ", "+") & ",+" & startState
sURL = sURL & "&daddr=" & Replace(endAddr, " ", "+") & ",+" & Replace(endCity, " ", "+") & ",+" & endState
sURL = sURL & "&hl=en"
Set oXH = CreateObject("msxml2.xmlhttp")
With oXH
.Open "get", sURL, False
.Send
BodyTxt = .RESPONSETEXT
End With
apan = Application.WorksheetFunction.Trim(apan)
apan = Mid(BodyTxt, InStr(1, BodyTxt, "<div class=""altroute-rcol altroute-info"">") + 49, 200)
apan = Left(apan, InStr(1, apan, "</span> </div>") - 1)
apan = Replace(apan, "</span>", "")
apan = Replace(apan, "<span>", "")
getGoogDistanceTime = apan
Set oXH = Nothing
End Function
Your code is written in VBScript, which is an Internet Explorer-only language. You need to rewrite it in JavaScript, which is understood by all the browsers.
You're also using IE-only code to do AJAX, using msxml2. That will need changing to use more generic AJAX code, using an XMLHttpRequest object.
I don't know what Application.WorksheetFunction.Trim() is, but you'll need to find a JavaScript alternative.

Resources