Login | |
|
 |
RE: XML to CSV in VBScript - 9/7/2005 10:11:53 AM
|
|
 |
|
| |
TNO
Posts: 1302
Score: 12
Joined: 12/18/2004
From: thenewobjective.com
Status: offline
|
What does the XML look like, and how do you want the CSV to look?
_____________________________
To iterate is human, to recurse divine. -- L. Peter Deutsch
|
|
| |
|
|
|
 |
RE: XML to CSV in VBScript - 9/7/2005 6:10:54 PM
|
|
 |
|
| |
Zifter
Posts: 318
Score: 0
Joined: 1/5/2005
From: Belgium
Status: offline
|
The reason why you get this error message is because in VbScript all variables are of the variant type. You can't specify the variable type when declaring variables in VbScript. The example from mconelly is in VBA! Check the XMLDOM object for handling XML files in VbScript http://www.devguru.com/Technologies/xmldom/quickref/xmldom_index.html Or do a search here on the forum HTH
|
|
| |
|
|
|
 |
RE: XML to CSV in VBScript - 9/7/2005 7:06:30 PM
|
|
 |
|
| |
Zifter
Posts: 318
Score: 0
Joined: 1/5/2005
From: Belgium
Status: offline
|
The page I linked to in my previous post contains examples in VbScript, not in Javascript. But the examples are VbScript to be included in a webpage (or HTA). Changing the "document.write" into "wscript.echo" should make those examples work as stand alone VbScripts (vbs,wsf) And here is one other post concerning the XMLDOM object: http://www.visualbasicscript.com/m_3465/tm.htm Try to see what you can come up with. If you have any problems or questions creating your script, feel free to post them here. HTH
|
|
| |
|
|
|
 |
RE: XML to CSV in VBScript - 9/7/2005 8:33:34 PM
|
|
 |
|
| |
Zifter
Posts: 318
Score: 0
Joined: 1/5/2005
From: Belgium
Status: offline
|
I'm sorry, but I don't understand your question. What is reading only the first line? Where? The InStr() function works with strings. strMyTestString = "ABCDEFG" WScript.Echo InStr(strMyTestString,"D") Output: 4 strMyTestString = "ABCDEFG" WScript.Echo InStr(strMyTestString,"Z") Output: 0
|
|
| |
|
|
|
 |
RE: XML to CSV in VBScript - 9/7/2005 8:41:33 PM
|
|
 |
|
| |
reloader
Posts: 72
Score: 0
Joined: 9/5/2005
Status: offline
|
Yes, sorry, I watched may code. Dim filesys, filetxt,contents, strKeyword strKeyword= "Wf" Const ForReading = 1, ForWriting = 4041, ForAppending = 8 Set filesys = CreateObject("Scripting.FileSystemObject") Set readfile = filesys.OpenTextFile("P:\b.txt", ForReading, False) contents = readfile.ReadLine() If InStr (112113,contents, strKeyword) > 0 Then Wscript.echo ("Found") Wscript.echo Instr Else Wscript.echo ("Not found") End If readfile.close So: I open a file, and the InStr contents is the Readline. But as I saw, the readline is reading only the first line in the file. How can I do, that it reads for instance the second line?
_____________________________
Ati
|
|
| |
|
|
|
 |
RE: XML to CSV in VBScript - 9/7/2005 8:59:31 PM
|
|
 |
|
| |
Zifter
Posts: 318
Score: 0
Joined: 1/5/2005
From: Belgium
Status: offline
|
There are a couple of ways to read an entire file. The ReadLine() method will indeed read the first line. Then "goes to the second line and waits for further instructions". If you would then invoke the ReadLine method again, it will read the second line and will go to the third line. strLine1 = readfile.ReadLine strLine2 = readfile.ReadLine If you want to handle each line you can put this in a loop Do Until readfile.AtEndOfStream contents = readfile.ReadLine If InStr(contents,strKeyword) > 0 Then ... End If Loop There is also a method called ReadAll(). This method will read the complete content of the file. So this would make: contents = readfile.ReadAll If InStr(contents,strKeyword) > 0 Then ... End If A third method Read(n) also exists. This will read "n" characters from the file and positions itself after that "n"-th character. But I don't think this is usefull for what you want to do. See where this will get you and don't hesitate to post your questions or problems.
|
|
| |
|
|
|
 |
RE: XML to CSV in VBScript - 9/7/2005 11:44:57 PM
|
|
 |
|
| |
Zifter
Posts: 318
Score: 0
Joined: 1/5/2005
From: Belgium
Status: offline
|
Something like this: strTest = "reverse0102" intPos = InStr(strTest,"s") strVariable = Mid(strTest,intPos + 1,3) WScript.Echo strVariable Remarks: 1. The red +1 is because the InStr functions finds the position of the searched character but we want to extract starting from the next character, thus +1 2. The InStr functions finds only the position of first occurence of the searched character. So in this example, if the string would have contained multiple times the letter "s", InStr would only find the position of the first "s". So be carefull with this! (There also exists another function called InStrRev, which does the same as the InStr function, but starts at the end of the string, so finding the position of the last occurence of the character to be found) HTH
|
|
| |
|
|
|
 |
RE: XML to CSV in VBScript - 9/8/2005 12:49:29 AM
|
|
 |
|
| |
Zifter
Posts: 318
Score: 0
Joined: 1/5/2005
From: Belgium
Status: offline
|
I suddenly notice...Are you trying to write your own XML parser? I don't think the effort is worth it. Don't re-invent the wheel. Did you take a look at that other post I linked to concerning the XMLDOM object?
|
|
| |
|
|
|
|
|