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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA and textboxes

Status
Not open for further replies.

usingVB

Programmer
Joined
Jan 1, 2009
Messages
8
Hi all,

I have a question about writing to textboxes using VB.

I have the following code which successfully writes to the immediate window, showing both data and frequency:

for example….

A 4
B 5
C 0
D 6
etc...

' Loop through the values returned by GetHistogram
For i = LBound(dataValues) To UBound(dataValues)

Debug.Print dataValues(i) & " " & dataFrequency(i)

Next i

End Sub

However, when I try to make this write to my textbox it only writes the last record, i.e...

D 6

the code I'm using is...

' Loop through the values returned by GetHistogram
For i = LBound(dataValues) To UBound(dataValues)

Form_Name.Textbox_name.Text = dataValues(i) & " " & dataFrequency(i)

Next i

End Sub



Can anybody help? I’m lost!

Cheers!


 
with to loop you keep on overwriteing the value
try
Code:
For i = LBound(dataValues) To UBound(dataValues)

Form_Name.Textbox_name.Text = Form_Name.Textbox_name.Text & Vbcrlf & dataValues(i) & "     " & dataFrequency(i)

Next i
 
Hi,

"However, when I try to make this write to my textbox it only writes the last record"

Think about it.
Code:
Form_Name.Textbox_name.Text = dataValues(i) & "     " & dataFrequency(i)
the FIRST time...
Code:
Form_Name.Textbox_name.Text = dataValues(i) & "     " & dataFrequency(i)
the SECOND time...

oops!!! Where's the FIRST value???

What are you attempting to do with this exersize?

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Cheers guy, that's a great help!

I've now managed to retun my list in for form:

A 2
B 4
C 8
D 1
etc...

Is there any way I can sum the frequency's to get a total and/or do a line count? I've had a look around on the net but can't seem to find any way to do this.

Cheers again, if you can help that would be great.

 
count will be
UBound(dataValues)+1
sum will be
Sumfreq=Sumfreq+dataFrequency(i)

 
Thanks pwise,

I've got the Count to work, but am struggling with the Sum bit. Sorry, I'm pretty new to this..., can you elaborate a bit further?

Cheers!
 
Apologies, I have now figured this out - thanks again!

I don't suppose you know of a way to select all text in a textbox do you? I can't seem to find this...

I was thinking something like...

Form_name.textbox_name.SelectAll

Any ideas?
 
Select All: for what purpose?

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top