write number zero to file

Author Message
WeBeScript

  • Total Posts : 11
  • Scores: 0
  • Reward points : 0
  • Joined: 11/28/2011
  • Status: offline
write number zero to file Sunday, December 04, 2011 5:17 AM (permalink)
0
hi
i'm trying to export data from excel to text file but i got into a problem when the cell contains a number zero
then vbscript treats it like a null string, and when it comes to write it to the text file then nothing is written
i tried the cstr function and also tried to insert it in double quotation marks but nothing helped
please help
thanks
 
#1
    59cobalt

    • Total Posts : 981
    • Scores: 91
    • Reward points : 0
    • Joined: 7/17/2011
    • Status: offline
    Re:write number zero to file Sunday, December 04, 2011 7:35 AM (permalink)
    5
    WeBeScript
    i'm trying to export data from excel to text file but i got into a problem when the cell contains a number zero then vbscript treats it like a null string, and when it comes to write it to the text file then nothing is written
    VBScript handles zeroes from Excel worksheets just fine. Please post your code.
     
    #2
      WeBeScript

      • Total Posts : 11
      • Scores: 0
      • Reward points : 0
      • Joined: 11/28/2011
      • Status: offline
      Re:write number zero to file Sunday, December 04, 2011 9:42 AM (permalink)
      0
      here is my script, when i open the text file and i look where its supposed to be the zero, i find nothing

      myDateString0 = FormatDateTime(Date(), 0)
      arrdate = split(myDateString0,"/")
      if arrdate(1) < 10 then
      strdate = "0" & arrdate(1)
      else
      strdate = arrdate(1)
      end if
      if arrdate(0) < 10 then
      stryear = "0" & arrdate(0)
      else
      stryear = arrdate(0)
      end if
      strfolderdate =  stryear & "-" & strdate & "-" & arrdate(2)
      strfolderyear = arrdate(2)
      textpath ="G:\Update\" & strfolderyear &"\" & strfolderdate &"\"
      Const adReadOnly = 1
      Const adOpenForwardOnly = 0
      Const adCmdText = &H0001
      Const ForWriting= 2
      Spreadsheet = textpath & "krtest.xlsm"
      Const Worksheet = "Sheet2"
      strFile = textpath & "FromExcel.txt"
      Set objFSO = CreateObject("Scripting.FileSystemObject")
      If objFSO.FileExists(Spreadsheet) Then
      Set objConnection = CreateObject("ADODB.Connection")
      Set objRecordSet = CreateObject("ADODB.Recordset")
      objConnection.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Spreadsheet & ";Extended Properties=Excel 12.0;" 
       objRecordset.Open "Select * FROM [" & Worksheet & "$A:I]", objConnection, adOpenForwardOnly, adReadOnly, adCmdText	
      Set objFile=objFSO.OpenTextFile(strFile, ForWriting, True)	
      Do Until objRecordSet.EOF	
      	sku = objRecordSet.Fields(0).Value	
      	description = objRecordSet.Fields(1).Value
      		size = objRecordSet.Fields(3).Value	
      	qty = objRecordSet.Fields(5).Value	
      	price = objRecordSet.Fields(6).Value
       arrsku = split(sku,"-")	
      	goodsku = arrsku(0) & arrsku(1)
      		if qty = "OUT" then qty = "0"		
      strline = goodsku & vbtab & description & vbtab & size & vbtab & qty & vbtab & price		
      If IsNull(strline) = False Then	
      		objFile.WriteLine strline	
      	End If	
      	objRecordSet.MoveNext	
      	strline = ""
      	Loop
      	objFile.Close	
      objConnection.Close
      End If
      wscript.echo "Done..." 
       
      #3
        WeBeScript

        • Total Posts : 11
        • Scores: 0
        • Reward points : 0
        • Joined: 11/28/2011
        • Status: offline
        Re:write number zero to file Monday, December 05, 2011 3:05 AM (permalink)
        0
        Ok i solved it my self
        since if the cell in excel was 0, then variable was equals "null" not zero, so i added an if statement, if the var qty is null then it should = "0"
        thanks any-way
         
        #4
          59cobalt

          • Total Posts : 981
          • Scores: 91
          • Reward points : 0
          • Joined: 7/17/2011
          • Status: offline
          Re:write number zero to file Monday, December 05, 2011 7:28 AM (permalink)
          5
          Glad to hear you got it resolved. Sorry I wasn't able to reply earlier, I just got home from work.
           
          As for the Null value: that's most likely due to the fact that you aren't using Excel, but a database interface to read the data.
           
          #5

            Online Bookmarks Sharing: Share/Bookmark

            Jump to:

            Current active users

            There are 0 members and 1 guests.

            Icon Legend and Permission

            • New Messages
            • No New Messages
            • Hot Topic w/ New Messages
            • Hot Topic w/o New Messages
            • Locked w/ New Messages
            • Locked w/o New Messages
            • Read Message
            • Post New Thread
            • Reply to message
            • Post New Poll
            • Submit Vote
            • Post reward post
            • Delete my own posts
            • Delete my own threads
            • Rate post

            2000-2012 ASPPlayground.NET Forum Version 3.9