I'm having problems writing to a seqential access file in VB 6

My.Computer.FileSystem.WriteAllText(path & "checkinfo.txt", _
                ourCheck.employee.PadRight(20) _
                & ourCheck.check.ToString("N2").PadLeft(10) _
                & ourCheck.chkdate.ToString("N2").PadLeft(10) _
                & ourCheck.total.ToString("N2").PadLeft(10) _
                & ControlChars.NewLine, True)

my debugging errors are 'padleft' is not a member of char...
any advise?

Yeah, that code is Not VB6 Code. In order to do something similar to what you have there:

open path & "checkinfo.txt" for output as #1  'or for append
     mydata = ourCheck.employee & string(20, " ")
     mydata = mydata & string(10, " ") & ourCheck.check
     mydata = mydata & string(10, " ") & ourCheck.chkdate
     mydata = mydata & string(10, " ") & ourCheck.total 
     mydata = mydata &  vbnewline
     print #1, ourCheck.employee & string(20, " ")
close #1

I'm not 100% sure that vb6 is even going to recognize whatever object "ourCheck" is, but in order to do the "ToString("N2")" you may have to look at using "Format$" in vb6 in order to format the string data.

I am having serious problems with VB recognizing the ourCheck object. All I'm trying to do is write four items to a sequential access file, and the only example of this I have uses the object code. No matter how I code it I cannot get it to work. I tried it like this:

Dim ourCheck As New franklinCheck

I get an error because franklinCheck is not a valid "type."

Dim ourCheck As Object

When I try to use the ourCheck object I get an error telling me that it's not defined.

I have no idea what I should do.

Well, the problem is that franklinCheck needs to be either a user defined type (UDT) in VB6, or you have to build a class module, and instantiate an instance of it. How is VB6 supposed to have any idea what franklinCheck is?

I knew it had no idea what franklinCheck was, but I couldn't figure out how to tell it. Nothing in my book tells me what to do in this case. All their examples seem to magically know what the user defined object is. I tried getting help from two other people and we are all clueless.

How do I define it as user defined?

Based on what is in the code that we are trying to write, it would look something like this:

public type franklinCheck
     Employee as string
     Check as string
     ChkDate as date
     Total as double
end type

dim ourCheck as franklinCheck
ourCheck.Employee = "Comatose"
ourCheck.Check = "S1812"
ourCheck.ChkDate = Format("01/10/2009", "mmm/dd/yyyy")
ourCheck.Total = 200.00

open path & "checkinfo.txt" for output as #1  'or for append
     mydata = ourCheck.employee & string(20, " ")
     mydata = mydata & string(10, " ") & ourCheck.check
     mydata = mydata & string(10, " ") & ourCheck.chkdate
     mydata = mydata & string(10, " ") & ourCheck.total 
     mydata = mydata &  vbnewline
     print #1, mydata
close #1

However, this method is probably NOT the same as what goes on with VB.NET.... in VB.NET, this is very likely an object (an instance of a class). In order to do so in VB6, you would have to build a class for it, which is a whole different beast (start by adding a "class module")

And actually, you could probably add the padding in the UDT, something like:

public type franklinCheck
     Employee as string * 10  ' <<--        Like This
     Check as string
     ChkDate as date
     Total as double
end type

But, You could only Pad on the right, not the left.

This article has been dead for over six months. Start a new discussion instead.