Conversion Problem Formatting QBASIC to VB6

I am having real problems converting PRINT Using statements in Quickbasic to Printer.print statements in VB6.

Is there a good book which outlines the method of formatting numbers and/or text in VB6 as I am on a merry goround trying to decipher M/S explanations and methods.

Or if one could give the VB6 code for formatting the following".

In QBASIC: print using "\ bbbbb\"; alphastr :rem prints up to 7 alpanumeric characters left aligned. b stands for space.

In QBASIC: Print using "####"; NUMBER : rem prints integers from 1 to 9999 right aligned

In QBASIC Print Using "####.##"; NUMBER : rem print floating point numbers form 0.0 to 9999.99 right aligned.

It is probably explained simply somewhere but I just can't find it. Any help would be appreciated Thanks.

With VB you can accomplish a lot of what you want with the format function. Other functions like Space, Len, and Me.TextWidth("string") would also be of help. Now, when printing with the printer object you can do one of two things. You can use the currentx/y properties to alter where you place your next piece of text or you can format the entire line with other functions like spc and tab (see Print Method in vb's help).


Good Luck

Once again Thanks for your input, looks as though I may have to use SPC and TAB as can't seem to get data straight in Columns using conventional VB6 code < Printer.print Format( value, "####") >.

Must be still in panic mode as I marked your response as Not Clear. Meant to mark it up as it was precisely what I needed. It is just that in QBASIC never had to use either SPC nor TAB to get the columns of output correctly aligned. Many Thanks.

Not a problem,... For future reference if you want to print things in colums, by not using spc or tab, build your output string before sending it to the printer...

Dim S As String, I As Integer
Printer.FontName = "Courier New" 'makes it easier to use mono spaced font
S = "Test Col 1" 'so far left aligned
'now next column is to be 40 characters from left but the colum is to be right aligned and the column is 3 characters wide (so positions 41-43)
I = 41 - Len("Test Col 1")
S = S & Space(I)
I = 3 - Len("12")
S = S & Space(I) & "12"
'and so on
Printer.Print S

However, that code can also be done like this...

Printer.Print "Test Col 1"; 'so far left aligned (it is the ; character that says not to goto the next line)
'now next column is to be 40 characters from left but the colum is to be right aligned and the column is 3 characters wide (so positions 41-43)
I = 41 - Len("Test Col 1")
S = S & Space(I)
I = 3 - Len("12")
Printer.Print Space(I) & "12";
'and so on

and another way would be to use the currentx/y properties (as I think I mentioned before)

Glad you solved it...

BTW, set for autoredraw to true and remove the printer part of printer.print and you can see a preview of what your output is like but once again you would have to do something like me.fontname = "courier new" to get the best results...

Good Luck

Many thanks will make it not only useful but clean as well. With scientific out put the old USING in printer statements did it very well and I could not replicate with needed change, but SPC and TAB have worked well. Cheers.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.