Formating strings in VB6
-
I am saving results to a text file and want my information to line up in nice little columns Name Status Extra Info Test A Pass 10.0 Test B with longer name Fail 7.5 Test C, short Name Pass 17.5 But what I get using VBTAB is inconsistent: Name Status Extra Info Test A Pass 10.0 Test B with longer name Fail 7.5 Test C, short Name Pass 17.5 Not sure if I can use a format function of not, documentation does not supply much info on format for text strings, just dates and numbers I understand the fonnts can not be a serif font, this is just for display to an operator
-
I am saving results to a text file and want my information to line up in nice little columns Name Status Extra Info Test A Pass 10.0 Test B with longer name Fail 7.5 Test C, short Name Pass 17.5 But what I get using VBTAB is inconsistent: Name Status Extra Info Test A Pass 10.0 Test B with longer name Fail 7.5 Test C, short Name Pass 17.5 Not sure if I can use a format function of not, documentation does not supply much info on format for text strings, just dates and numbers I understand the fonnts can not be a serif font, this is just for display to an operator
Hello No-e, You have to write the data as fixed length column files. Determine your output fields and find out the best fit MAX length of the data for each column. Then use VB/VB.net LSet(), RSet() functions are Trim() functions to write your columns in fixed length. Hope this will help you solve your problem. Nathhani
-
I am saving results to a text file and want my information to line up in nice little columns Name Status Extra Info Test A Pass 10.0 Test B with longer name Fail 7.5 Test C, short Name Pass 17.5 But what I get using VBTAB is inconsistent: Name Status Extra Info Test A Pass 10.0 Test B with longer name Fail 7.5 Test C, short Name Pass 17.5 Not sure if I can use a format function of not, documentation does not supply much info on format for text strings, just dates and numbers I understand the fonnts can not be a serif font, this is just for display to an operator
A text file has no formatting capabilities, so you have to use spaces to line them up, and specify for anyone who will be using it to use a non-proporional font when displaying it. You can use alignment in composite formatting to line up the columns. Example from MSDN:
string myFName = "Fred";
string myLName = "Opals";
int myInt = 100;
string FormatFName = String.Format("First Name = |{0,10}|", myFName);
string FormatLName = String.Format("Last Name = |{0,10}|", myLName);
string FormatPrice = String.Format("Price = |{0,10:C}|", myInt);
Console.WriteLine(FormatFName);
Console.WriteLine(FormatLName);
Console.WriteLine(FormatPrice);FormatFName = String.Format("First Name = |{0,-10}|", myFName);
FormatLName = String.Format("Last Name = |{0,-10}|", myLName);
FormatPrice = String.Format("Price = |{0,-10:C}|", myInt);
Console.WriteLine(FormatFName);
Console.WriteLine(FormatLName);
Console.WriteLine(FormatPrice);Example output:
First Name = | Fred|
Last Name = | Opals|
Price = | $100.00|
First Name = |Fred |
Last Name = |Opals |
Price = |$100.00 |--- b { font-weight: normal; }
-
A text file has no formatting capabilities, so you have to use spaces to line them up, and specify for anyone who will be using it to use a non-proporional font when displaying it. You can use alignment in composite formatting to line up the columns. Example from MSDN:
string myFName = "Fred";
string myLName = "Opals";
int myInt = 100;
string FormatFName = String.Format("First Name = |{0,10}|", myFName);
string FormatLName = String.Format("Last Name = |{0,10}|", myLName);
string FormatPrice = String.Format("Price = |{0,10:C}|", myInt);
Console.WriteLine(FormatFName);
Console.WriteLine(FormatLName);
Console.WriteLine(FormatPrice);FormatFName = String.Format("First Name = |{0,-10}|", myFName);
FormatLName = String.Format("Last Name = |{0,-10}|", myLName);
FormatPrice = String.Format("Price = |{0,-10:C}|", myInt);
Console.WriteLine(FormatFName);
Console.WriteLine(FormatLName);
Console.WriteLine(FormatPrice);Example output:
First Name = | Fred|
Last Name = | Opals|
Price = | $100.00|
First Name = |Fred |
Last Name = |Opals |
Price = |$100.00 |--- b { font-weight: normal; }
The example is for VB.NET though... will need to pad with spaces in VB6. Chandra