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... -
Dim handle As Integer
-
Dim sInhalt As String
-
-
handle = FreeFile
-
-
Open strFilename For Binary As #handle
-
sInhalt = Space$(LOF(handle))
-
Get #handle, , sInhalt
-
Close #handle
-
-
Now writing the read value to output in a text box.
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
8 1787
Hi,
Use "Microsoft Script Control"
Regards
Veena
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....
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
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???
Hi,
Add References "Microsoft Script RunTime" to ur project and a new Command button (cmdNew) and place this code in cmdNew_Click event : -
Private Sub cmdNew_Click()
-
'
-
Dim FSO As New FileSystemObject
-
Dim TArr
-
Dim fsStr As TextStream
-
Dim NewString As String
-
Dim FindStr As String
-
Dim i As Integer
-
Dim j As Integer
-
Dim LineNo As Integer
-
Dim TempStr As String
-
'
-
NewString = ""
-
FindStr = ""
-
LineNo = 0
-
'
-
Set fsStr = FSO.OpenTextFile(App.Path & "\xmlinput.txt", ForReading)
-
TArr = Split(fsStr.ReadAll, vbCrLf)
-
NewString = TArr(0)
-
'ASSUMING ONE LINE IN XML FILE
-
'FOR MULTIPLE LINES IN XML, LOOP
-
fsStr.Close
-
Set TArr = Nothing
-
'
-
i = InStr(UCase(NewString), "GETCONTENT")
-
If i > 0 Then
-
FindStr = Mid(NewString, i)
-
j = InStr(FindStr, "(")
-
If j > 0 Then
-
LineNo = Val(Mid(FindStr, (j + 1)))
-
End If
-
End If
-
'
-
Set fsStr = FSO.OpenTextFile(App.Path & "\sample1.txt", ForReading)
-
TArr = Split(fsStr.ReadAll, vbCrLf)
-
fsStr.Close
-
'
-
LineNo = LineNo + 1
-
If LineNo > 0 And LineNo <= UBound(TArr) Then
-
TempStr = TArr(LineNo)
-
j = InStr(TempStr, ":")
-
If j > 0 Then
-
TempStr = Trim(Mid(TempStr, (j + 1)))
-
TempStr = Replace(TempStr, Chr(9), "")
-
End If
-
End If
-
'
-
NewString = Replace(NewString, """", "")
-
i = InStr(UCase(NewString), "GETCONTENT")
-
If i > 0 Then
-
j = InStr(i, NewString, "&")
-
NewString = Left(NewString, (i - 3)) & """" & TempStr & """" & Mid(NewString, (j + 1))
-
RTB.Text = NewString
-
End If
-
'
-
Set FSO = Nothing
-
'
-
End Sub
-
-
It gives u basic idea, how u can parse the textfile..
u can refine the code
Regards
Veena
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???
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
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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
|
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...
|
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...
|
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),...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
| |