Read Variable As Text

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
kpassaur
Automation Wizard
Posts: 696
Joined: Wed Jul 07, 2004 1:55 pm

Read Variable As Text

Post by kpassaur » Tue Dec 15, 2009 10:58 am

This is a script that will test a database conneciton string and SQL Statement in MS. It works on the first run but naturally when refreshed it displays the variable as the variable instead of the text. I know that sounds confusing, but if you copy and paste the code you will see what I mean.

The line that contains '%ID%' (which is displayed on msEdit2) needs to be refreshed the same way as origionally entered not with the value from the variable in it after it has run. I have tried it a few different ways with no sucess.

Also when creating this I came accross a program called "Any SQL Mastro" which has a really neat tool that creates a connection string from a Wizard that can be copied and pasted into MS. It is available here and is freeware
http://www.sqlmaestro.com/products/anysql/ - there is also a licensed version with more features.

This is code I need help with

IfFileExists>C:\temp\dataconnection.txt
ReadLn>C:\temp\dataconnection.txt,1,CS
ReadLn>C:\temp\dataconnection.txt,2,SQLS
Else
Let>CS=
Let>SQLS=
// Remove two lines below when finished
Let>CS=Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=AdventureWorks;Data Source=ATHLON-VISTA\SQLEXPRESS
Let>SQLS=Select Name From Sales.Store Where CustomerID = '%ID%'

Endif

Dialog>Dialog1
Caption=Test Database Connection
Width=800
Height=418
Top=CENTER
Left=CENTER
Max=0
Min=0
Close=1
Resize=0
Edit=msEdit1,17,114,750,%CS%
Label=Data Connection String,337,96,true
Label=SQL Select Statement,339,144,true
Edit=msEdit2,17,162,750,%SQLS%
Label=In the SQL Statement the value passed from the barcode should be entered as ‘%ID%’,188,192,true
Label=Example: Select Name From Sales.Store Where CustomerID = '%ID%',223,216,true
Edit=msEdit3,339,251,106,
Label=To test the connection enter a value to search for in the box above and click on 'Test',189,288,true
Button=Test,595,328,75,25,1
Button=Exit,669,328,75,25,2
EndDialog>Dialog1


Show>Dialog1
Label>MainLoop
GetDialogAction>Dialog1,result
If>result=2,finish
If>result=1,Test
Wait>0.1
Goto>MainLoop



SRT>Test
CloseDialog>Dialog1
WriteLn>%TEMP_DIR%\tempset.txt,result,%Dialog1.msEdit1%
WriteLn>%TEMP_DIR%\tempset.txt,result,%Dialog1.msEdit2%
WriteLn>%TEMP_DIR%\tempset.txt,result,%Dialog1.msEdit3%

Let>connstr=%Dialog1.msEdit1%
Let>SQL=%Dialog1.msEdit2%
Let>ID=%Dialog1.msEdit3%
DBConnect>connstr,dbH
Let>VAREXPLICIT=1
DBQuery>%dbH%,%SQL%,match,numRecs,numFields
Let>VAREXPLICIT=0
DBClose>dbH
If>%numRecs%=0
MDL>No Match
Else
Let>datamatch=match_1_1
MDL>The match is %datamatch%
Endif

ReadLn>%TEMP_DIR%\tempset.txt,1,L1
ReadLn>%TEMP_DIR%\tempset.txt,2,L2
ReadLn>%TEMP_DIR%\tempset.txt,3,L3


Let>Dialog1.msEdit1=%L1%
Let>Dialog1.msEdit2=%L2%
Let>Dialog1.msEdit3=%L3%
ResetDialogAction>Dialog1

Show>Dialog1
END>Test



Label>finish
Exit>0

User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Tue Dec 15, 2009 6:12 pm

Hi Keith.

I may be misinterpreting your question but....

What happens if you delete the file in which you stored the edit box values immediately after you read back the values. You only ever read the first three lines so if you don't delete the file the first three lines will never change.

///your script....

ReadLn>%TEMP_DIR%\tempset.txt,1,L1
ReadLn>%TEMP_DIR%\tempset.txt,2,L2
ReadLn>%TEMP_DIR%\tempset.txt,3,L3

//add the next line
DeleteFile>%TEMP_DIR%\tempset.txt,

///....the rest of your script

kpassaur
Automation Wizard
Posts: 696
Joined: Wed Jul 07, 2004 1:55 pm

Read as Text

Post by kpassaur » Tue Dec 15, 2009 7:00 pm

I dont' think that will make a difference as they were written correctly and read back. Once read back the variable is read again. However, this seems to work and I believe it is because %ID% is never used.

CloseDialog>Dialog1
DeleteFile>%TEMP_DIR%\tempset.txt
WriteLn>%TEMP_DIR%\tempset.txt,result,%Dialog1.msEdit1%
WriteLn>%TEMP_DIR%\tempset.txt,result,%Dialog1.msEdit2%
WriteLn>%TEMP_DIR%\tempset.txt,result,%Dialog1.msEdit3%

Let>connstr=%Dialog1.msEdit1%
Let>SQL=%Dialog1.msEdit2%
StringReplace>%SQL%,'%ID%',%Dialog1.msEdit3%,SQL
DBConnect>connstr,dbH
Let>VAREXPLICIT=1
DBQuery>%dbH%,%SQL%,match,numRecs,numFields
Let>VAREXPLICIT=0
DBClose>dbH

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