Add letters to a value read from a db

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
ZeitenWanderer
Pro Scripter
Posts: 68
Joined: Wed Dec 07, 2005 7:13 am

Add letters to a value read from a db

Post by ZeitenWanderer » Wed Mar 19, 2014 7:40 am

Need to get familiar with a script from someone else and am all new to this tool.

This is the line I need to enhance:

ts.Write rs.Fields("Nachname_Autor") & rs.Fields("Vorname_Autor") & vbTab

I need to place a comma and a space among these two values. Checked the help, but could find where to start. Any hints?

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Wed Mar 19, 2014 7:59 am

That is VBScript. Do this:

ts.Write rs.Fields("Nachname_Autor") & ", " & rs.Fields("Vorname_Autor") & vbTab

That will insert comma followed by space (", ") between the two fields.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

ZeitenWanderer
Pro Scripter
Posts: 68
Joined: Wed Dec 07, 2005 7:13 am

Did it and next issue appears

Post by ZeitenWanderer » Wed Mar 19, 2014 10:12 am

Thanks, that did the trick and opened two new questions:

Following the example, I added this value to another line:

ts.Write "http://www.anypage.com/pics/" & rs.Fields("Image") & vbTab

Works - but it also inserts the http://www.anypage.com/pics/ in the outcoming csv-export-file, when the field in the db is actually empty.

How would one check for empty fields and avoid an unnecessary entry?


Next, if one wants to select a certain field, and depending on its content, change a value - how to?

I checked http://www.mjtnet.com/vbsdb.htm and some proceeding pages, but seem to be too awkward (or too impatient:-)) to find an exact example.

This is the code:

VBSTART
Function GetData(Quantity,Sonderangebot)
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim SQLString
Dim Value
Dim TextLine
Dim strSafeTime
Dim strSafeDate
Dim ProjectFolder

ProjectFolder="C:\darp_lokal\Daten"

set MyDB = CreateObject("ADODB.Connection")
MyDB.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\darp_lokal\Daten\DARP_DB.mdb"

strSafeTime = Right("0" & Hour(Now), 2) & Right("0" & Minute(Now), 2) & Right("0" & Second(Now), 2)
strSafeDate = replace(FormatDateTime(now,2),"/","")



SQLString = "select * from tblBuchdaten where quantity >=1"

Set fs = CreateObject("Scripting.FileSystemObject")

Set ts = fs.CreateTextFile(ProjectFolder & "\export_amazon" & strSafeDate & "-" & strSafeTime & ".txt")


' Open the file for input.
Set MyFile = fs.OpenTextFile(ProjectFolder & "\export_amazon_header.txt", ForReading)
' Read from the file and display the results.
Do While MyFile.AtEndOfStream GetData("%Quantity%","%Sonderangebot%"),Message
MessageModal>%Message%

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Wed Mar 19, 2014 10:35 am

So make sure it's not empty first:

Code: Select all

If rs.Fields("Image") <> "" Then
   ts.Write "http://www.anypage.com/pics/" & rs.Fields("Image") & vbTab
Endif
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts