Stupid VB 6 Issue. Help.

Codewiz

Diamond Member
Jan 23, 2002
5,758
0
76
Ok I have a new stupid problem. It has to do with formatting string correctly.

ATTENTION. Obviously the forum doesn't support correct formatting so the output is screwed up. Let me describe what the problem is.

The price 2.30 moves one place to the right everytime the length of item is increased BUT it should not since I am taking the length of Item into account for spacing.

FIGURED THIS OUT: Text and spaces don't take up the same amount of space. That is why the text is not staying formatted correctly. Anyone know a font where a space takes up the same area as characters?



here is what I am doing in a textbox:

txtorder.Text = txtorder.Text & "Order for " & txtName.Text & ":" & _
vbCrLf & "Item" & Space$(25) & "Price" & Space$(10) _
& "Quantity" & Space$(10) & "Cost" & vbCrLf
spaces = 25 - Len(txtItem.Text)
txtorder.Text = txtorder.Text & txtItem.Text & Space$(spaces) & txtPrice.Text & vbCrLf



I get out put like this
Order for Jon Doe:
Item Price Quantity Cost
Apples 2.30
Order for Jon Doe:
Item Price Quantity Cost
Apples2 2.30
Order for Jon Doe:
Item Price Quantity Cost
Apples23 2.30



As you see the price(2.30) keeps moving to the right even though I am supposidly using less spaces. Apples are the txtItem.text.

I can't figure out why it keeps creating extra spaces in the output eventhough I am taking into account how long the txtItem is.

The last line of code is the problem.

Help.

Jim
 

Codewiz

Diamond Member
Jan 23, 2002
5,758
0
76
Courier New is the font that is consistent between spaces and characters.

Jim
 

RedFox1

Senior member
Aug 22, 2000
587
0
76
Hmm...it looks OK to me. Obviously there's a problem...but what you've got here looks correct.

My .02
-Russ
 

Codewiz

Diamond Member
Jan 23, 2002
5,758
0
76
Now I have another stupid problem. I am doing things with currency but I can't get it to represent $2.60. It always does $2.6.

It is really pissing me off. I am starting to realize why I never should have started VB. Give me C/C++ or Java any day of the week.

Jim
 

bot2600

Platinum Member
May 18, 2001
2,075
0
76
A complex but consistant trick I use when formatting text would be to use a label with a border and put 3 text boxes or label on top of it side by side without borders and put the first column of information in the left textbox/label, and the second column of information in the second textbox/label and the third in the third. Then there is no need for spacing as everything is left justified anyhow. Hope that wasnt too confusing.

Bot
 

minendo

Elite Member
Aug 31, 2001
35,557
16
81
For the output to display in dollars like $2.60 use the below code:

Format(txtPrice.text, "$0.00")

That should fix your problem.
 

Codewiz

Diamond Member
Jan 23, 2002
5,758
0
76
This is what I have and it still doesn't work.

cost = CCur(CDbl(txtPrice.Text) * CDbl(txtQuantity.Text))
total = total + cost
cost = Format(cost, "$0.00")
txtorder.Text = txtorder.Text & txtItem.Text & Space(19 - Len(txtItem.Text) - Len(txtPrice.Text)) & txtPrice.Text & Space(13 - Len(txtQuantity.Text)) & txtQuantity.Text & Space(9 - Len((cost))) & cost & vbCrLf


I just can't figure out what the stupid issue is.

Jim
 

bot2600

Platinum Member
May 18, 2001
2,075
0
76
Try this. I made a quick project that I think does what you want. It has all the little amenities, the submit button isnt valid until all of the data is filled in and the submit button is default when you press return. Then again, I am may be totally not understanding what you are trying to do. This is the source.

Bot
 

Codewiz

Diamond Member
Jan 23, 2002
5,758
0
76
Everything on mine works fine except the formatting of the currency. I am going to work on it some more later tonight.

Jim
 

bot2600

Platinum Member
May 18, 2001
2,075
0
76
cost = CCur(CDbl(txtPrice.Text) * CDbl(txtQuantity.Text))
total = total + cost
cost = Format(cost, "$0.00")
txtorder.Text = txtorder.Text & txtItem.Text & Space(19 - Len(txtItem.Text) - Len(txtPrice.Text)) & txtPrice.Text & Space(13 - Len(txtQuantity.Text)) & txtQuantity.Text & Space(9 - Len((cost))) & cost & vbCrLf

should be:
cost = CCur(CDbl(txtPrice.Text) * CDbl(txtQuantity.Text))
total = total + cost
txtorder.Text = txtorder.Text & txtItem.Text & Space(19 - Len(txtItem.Text) - Len(txtPrice.Text)) & txtPrice.Text & Space(13 - Len(txtQuantity.Text)) & txtQuantity.Text & Space(9 - Len((cost))) & format(cost,"$0.00") & vbCrLf

Bot
 

bot2600

Platinum Member
May 18, 2001
2,075
0
76
Or I would actually write it as

cost = Int(txtPrice) * Int(txtQuantity)
total = total + cost
txtorder= txtorder & txtItem & Space(19 - Len(txtItem) - Len(txtPrice)) & txtPrice & Space(13 - Len(txtQuantity)) & txtQuantity & Space(9 - Len((cost))) & format(cost,"$0.00") & vbCrLf
 

Codewiz

Diamond Member
Jan 23, 2002
5,758
0
76
One problem with what you wrote:

Space(9 - Len((cost)))

Will screw up the formatting

I will try to do a space(9-Len(format(cost,"$0.00") ))

Jim
 

Codewiz

Diamond Member
Jan 23, 2002
5,758
0
76
Bot2600,

I appreciate the help. The format fixed it once I used the Len(format(cost,"$0.00"))

Thanks again,

Jim