Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying a string with proper alignment

Status
Not open for further replies.

realace112

Programmer
Jul 28, 2002
8
US
Suppose I have a long character string like this:

"ID: 4343 Value: $4,234 Method: App;
ID: 23 Value: $350 Method: Val;
ID: 232 Value: $250,000 Method: Seg;"

the fields are all out of alignment. here is what I am trying to make it look like.
"ID: 4343 Value: $4,234 Method: App;
ID: 23 Value: $350 Method: Val;
ID: 232 Value: $250,000 Method: Seg;"

I am getting these values back from an xml collection and just concatenating each value to the string to create this one long string. But I'd like to figure out how to align them properly. Is there any special formatting function I can use? By the way, this is in VBScript. Thanks
 
where is this long string coming from? I text file?

I love small animals, especially with a good brown gravy....
 
I am getting the values by parsing through an xml collection. Here is the psuedocode

XmlDOM = xmldoc.selectsinglenode(//some xml path)
String = ""
For each Node in XMLDOM
String = String & "ID: " & Node.GetAttribute("ID")
String = String & "Value: " & Node.GetAttribute("Value")
String = String & "Method: " & Node.GetAttribute("Method")
insert a new line
Next

I'm going to also be checking to see if any of the field exists before I add it to the string. Because there may not even be a value for each field.
 
Ok, it's not going to be as hard to do than I originally thought.

Where is your output going to be? a file or a GUI display?

I love small animals, especially with a good brown gravy....
 
well you could try putting a tab after each value:
String = String & "ID: " & Node.GetAttribute("ID") & vbTab

What are you ultimately going to do with the string? maybe there is another way... like formatting it on the output side of your process.
 
The contents of the string are going to be inserted into a Word document form. Nothing real fancy but the string needs to be aligned properly to be easier on the eyes.

I thought about using tabs but the problem is that the data values need to be right justified.
 
Where is this scripting going to run? VB or a webpage or just a vbs file?

I love small animals, especially with a good brown gravy....
 
Since you are going to put it into a Word form, perhaps you shouldn't worry about the layout coming from the source and rather format the Word document instead. You might even be able to format the form element controls. Another possibility is the use of Bookmarks within a word tabale. Then you can programatically iterate through the form elements or booksmarks and insert the data that way.
 
Basically, I'm doing token processing. I insert a token on the page that maps to this script that I am writing. The script in fact is stored in the database and it runs client-side. The output of this script (the string) shows in place of where the token is when the form is opened. Changing it on the word page layout doesn't sound like a bad idea.
 
Another thing you could do is just force it for each field.

Imagine field "ID" is 10 characters long and "Value" is 12 characters long:
Code:
String = String  & Right(Space(10) & SpaceNode.GetAttribute("ID"), 10)

String = String  & Right(Space(12) & SpaceNode.GetAttribute("Value"), 12)

You could do this... and it would work... but you'd have to know the size of each field. You could either know in advance, or perhaps calculate this at run-time.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top