473,385 Members | 1,344 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Convert Text to VB Command

Hi All,
There is a text file with content for example
now()
In vb i will read the content of this text file and then i want to execute this as a vb command. How to do that?

Below is flow...

Expand|Select|Wrap|Line Numbers
  1.   Dim handle As Integer 
  2.   Dim sInhalt As String 
  3.  
  4.   handle = FreeFile 
  5.  
  6.   Open strFilename For Binary As #handle 
  7.   sInhalt = Space$(LOF(handle)) 
  8.   Get #handle, , sInhalt 
  9.   Close #handle 
  10.  
  11.  
Now writing the read value to output in a text box.

Expand|Select|Wrap|Line Numbers
  1.   Text1.Text = sInhalt 

Now if we execute this program, i'm getting only now() in the Text1
control instead i want 10/3/2007 7:09:11 PM in the text1 control. How
to do this is my question..... Similiary any command can be written in
the file and if we execute then vb should read the content of the text file and find recognize as command and not text and execute it.... How to do this??? Any api or logic ....???

OS: Windows
Language: VB6
Oct 4 '07 #1
8 1787
QVeen72
1,445 Expert 1GB
Hi,

Use "Microsoft Script Control"

Regards
Veena
Oct 4 '07 #2
Hi Veena,
Actually my requirement is some thing like this...

I'm writing a parser which has standard xml format which will be written in a file like this
"<TESTDATA><FACTORY NAME=""SAKTHI"" TESTER=""" & Getcontent(97, ":", 1) & """ /></TESTDATA>"

and this parser has to watch a folder constantly and then once file is dropped then the parser should read the contents and then execute this xml which means Getcontent(97, ":", 1) has to be translated as "Passed" . "Passed" is nothing but the string in the 97th line's first value of the tester log after splitting using : ...

97th line is as below
H UUT Result: Passed

so whenever any file is dropped into that folder the parser reads the file and then reads the xml from the xmlinput.txt file and then translates the xml....

This xml will vary incase if we are asked to read some more contents in 4th line and 8th line....

So now if i read the content of the xmlinput.txt and then write it to a RichTextbox, vb just just writes as it is
"<TESTDATA><FACTORY NAME=""SAKTHI"" TESTER=""" & Getcontent(97, ":", 1) & """ /></TESTDATA>"

but instead i want
<TESTDATA><FACTORY NAME=""SAKTHI"" TESTER="Passed" /></TESTDATA>

How to do this????? Scripting has some limits since some of the vbcommands wont work and Memory Management is very important for parser....
Oct 4 '07 #3
QVeen72
1,445 Expert 1GB
Hi,

OK, in that case, Script Control is not going to help you, you have to write a Parser of your own, Open the file, and check for the key word. And go to that line, and more over, not very sure, if Rich Text box is going to help you.
Open the file using FSO and start parsing each line and save in some other file.

REgards
Veena
Oct 4 '07 #4
Hi All,

Click here to download Parser Source Code

Please check the attachment for my sample source code which tells what i need ultimately.... Microsoft scripting has some limitations and memory management issues... So Please suggest some method...

Once you run the exe in the attachment or in vbp you can see two command buttons. If you click on the first button... the xml string is read from a text file and then displayed in the text box and if you click the command button 2 you can see a string of xml is displayed in the text box...

My Requirement is command1's output should come like command2's output... How to do?? Any API or Idea or Tips???
Oct 4 '07 #5
QVeen72
1,445 Expert 1GB
Hi,

Add References "Microsoft Script RunTime" to ur project and a new Command button (cmdNew) and place this code in cmdNew_Click event :

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdNew_Click()
  2.     '
  3.     Dim FSO As New FileSystemObject
  4.     Dim TArr
  5.     Dim fsStr As TextStream
  6.     Dim NewString As String
  7.     Dim FindStr As String
  8.     Dim i As Integer
  9.     Dim j As Integer
  10.     Dim LineNo As Integer
  11.     Dim TempStr As String
  12.     '
  13.     NewString = ""
  14.     FindStr = ""
  15.     LineNo = 0
  16.     '
  17.     Set fsStr = FSO.OpenTextFile(App.Path & "\xmlinput.txt", ForReading)
  18.     TArr = Split(fsStr.ReadAll, vbCrLf)
  19.     NewString = TArr(0)
  20.     'ASSUMING ONE LINE IN XML FILE
  21.     'FOR MULTIPLE LINES IN XML, LOOP
  22.     fsStr.Close
  23.     Set TArr = Nothing
  24.     '
  25.     i = InStr(UCase(NewString), "GETCONTENT")
  26.     If i > 0 Then
  27.         FindStr = Mid(NewString, i)
  28.         j = InStr(FindStr, "(")
  29.         If j > 0 Then
  30.             LineNo = Val(Mid(FindStr, (j + 1)))
  31.         End If
  32.     End If
  33.     '
  34.     Set fsStr = FSO.OpenTextFile(App.Path & "\sample1.txt", ForReading)
  35.     TArr = Split(fsStr.ReadAll, vbCrLf)
  36.     fsStr.Close
  37.     '
  38.     LineNo = LineNo + 1
  39.     If LineNo > 0 And LineNo <= UBound(TArr) Then
  40.         TempStr = TArr(LineNo)
  41.         j = InStr(TempStr, ":")
  42.         If j > 0 Then
  43.             TempStr = Trim(Mid(TempStr, (j + 1)))
  44.             TempStr = Replace(TempStr, Chr(9), "")
  45.         End If
  46.     End If
  47.     '
  48.     NewString = Replace(NewString, """", "")
  49.     i = InStr(UCase(NewString), "GETCONTENT")
  50.     If i > 0 Then
  51.         j = InStr(i, NewString, "&")
  52.         NewString = Left(NewString, (i - 3)) & """" & TempStr & """" & Mid(NewString, (j + 1))
  53.         RTB.Text = NewString
  54.     End If
  55.     '
  56.     Set FSO = Nothing
  57.     '
  58. End Sub
  59.  
  60.  
It gives u basic idea, how u can parse the textfile..
u can refine the code


Regards
Veena
Oct 4 '07 #6
Hi Veena,
Thanks for your reply! i also thought of same logic but then was waiting for some api stuffs which can directly execute the statement... Is there any other shortway with which like

StrxmlOut = Execute(xmlfilecontent)

RTB.Text = Strxmlout

Something like this???
Again, Thanks for your reply.... Also ||'ly one more clarification... FSO is better or OPEN ing file in Binary mode is better???
Oct 4 '07 #7
QVeen72
1,445 Expert 1GB
Hi,

Always FSO is better. It is meant for better file operations. Comparatively it is faster also.
In one go, "ReadAll" can transfer the contents from file to an array. Once you have all the contents in an array, you can do all the parsing/rearranging easily. With File IO you need to open and read line by line just to count number of lines.

REgards
Veena
Oct 5 '07 #8
Killer42
8,435 Expert 8TB
Always FSO is better. It is meant for better file operations. Comparatively it is faster also.
In one go, "ReadAll" can transfer the contents from file to an array. Once you have all the contents in an array, you can do all the parsing/rearranging easily. With File IO you need to open and read line by line just to count number of lines.
That's just not true.

FSO does generally provide better functionality. But I doubt that it's any faster. If you open a file in Binary mode, you can also transfer the entire thing into a string or an array in one go.

Generally, I would recommend using FSO, as it provides lots of great functionality for dealing with drives, folders and files. But it should also be noted that it does have one or two small drawbacks. For instance...
  • It requires additional of a reference to your project.
  • It requires slightly more complex coding, compared to the built-in file processing.
  • As I've recently learned the hard way, if you do use it to process a file line-by-line, it doesn't provide any way to track your progress your progress. In other words, you can't tell where you're up to.
Oct 5 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Paul | last post by:
How would I convert the contents of a textbox into text files. Say I have a textbox containin the following... 13-02-00 - Paul Oakenfold 06-02-00 - William Orbit 30-01-00 - Laurent Garnier...
2
by: Phil Stanton | last post by:
When designing a new form or report, the Default ForeColor is often something like -2147483640 which is the colour of Windows text (possibly black) and the default backColor is -2147483643...
8
by: Assimalyst | last post by:
Hi i have a value entered into an asp text box, procedureDateTxtBx.Text, thet has the format dd/MM/yyyy. I need to convert this into a format recognisable by SQL server in order to properly query...
4
by: velu | last post by:
I have created a table MSSQL that contain values and published into Datagrid. The table is typically like this.. Tbl Article Rating Count 1 3 3 2 0 0 3 2 1 4 4 5
3
by: GM | last post by:
Dear all, Could you all give me some guide on how to convert my big5 string to unicode using python? I already knew that I might use cjkcodecs or python 2.4 but I still don't have idea on what...
2
by: thecamisland | last post by:
I'm trying to communicate with Durant Ambassador counter through serial port. All I have is an old piece of BASIC code. I have managed to convert a portion of this old BASIC code to VB6 and I can...
4
by: Franky | last post by:
I have a Command Prompt window open and select all the characters and copy them to the clipboard. I then read them from the clipboard str = CType(DataO.GetData(DataFormats.OemText, False),...
3
by: James | last post by:
See the following example. db2 =create table aaa (c1 decimal(10,3)); DB20000I The SQL command completed successfully. db2 =insert into aaa values (200.03); DB20000I The SQL command...
0
daJunkCollector
by: daJunkCollector | last post by:
Hey, I found the following code and I am attempting to convert it so that it works in conjunction with my MS Access database: using System; using System.Data; using...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.