PDA

View Full Version : formatting & updating a group textboxes



northernstar
10-05-2007, 10:17 AM
hi everyone

i got some help via another thread which was very useful in formatting of textboxes in my form

but i was wondering if it is possible to format a group of textboxes on the same form with the same format, as i have quite alot of textboxes which need formatting depending on the entry of another textbox

please find below the a sample of the code i am using at the moment

If DecimalPlaces = 0 Then
Nominal1b = Format(Nominal1b, "0")
Nominal2b = Format(Nominal1b, "0")
Else
Nominal1b = Format(Nominal1b, "0." & String(DecimalPlaces, "0"))
End If

thanks in advance

Bob Phillips
10-05-2007, 10:26 AM
That is exactly what we showed you in the other thread.

northernstar
10-05-2007, 10:26 AM
hi again

please find below a sample piece of code that i have to repeat for a group of textboxes starting with Reading1 to Reading11, Reading1a to Reading11a and Reading1b upto Reading11b, and the same for Corrected, PassFail, Nominal and Error (all the textboxes in the 1 series are compared, same with the 1a series and so obviously this will need to be reflected in the code)

i really wanted the textboxes to update/change as necessary in real time
suppose i could have the code in the last box and then update all the other boxes at the end

any other ideas or suggestions


Private Sub Reading1ba_Change()

' allows changes to reading1 and updates error1 straight away

If Reading1ba = "" Then
Error1ba = ""
Exit Sub
Else
Error1ba = (Reading1ba - Corrected1ba)
End If

If Nominal1ba > Tolerance01 And Nominal1ba < Tolerance09 Then
PassFail1ba = ToleranceA
Else
PassFail1ba = ToleranceB
End If

If Abs(Error1ba) < PassFail1ba Then
PassFailA1a = ""
Else
PassFailA1a = "*"
End If

If Reading1b = "" Then
PassFailA1a = ""
End If

End Sub

if you require any further information please let me know
thanks in advance

Bob Phillips
10-05-2007, 10:30 AM
Just extend the subroutine procedure that we showed before.

lucas
10-05-2007, 10:30 AM
Threads merged.

It doesn't help to post the same question in multiple threads.

northernstar
10-05-2007, 10:32 AM
so i understand that i can expand this code, but before i started typing in all the code i thought i would ask if you can do it in groups

but guessing not

thanks

Bob Phillips
10-05-2007, 10:34 AM
I am sure that the answer will be yes (anything is possible if you have the will, the money and the time), but I am not sure what you mean by '... do it in group'.

northernstar
10-05-2007, 10:50 AM
have no money.......

what i mean by a group:

say i have 10 textboxes named a1 to a10 and i want to format them to a number of decimal places depending on textbox dp

rather than typing the code



If dp = 0 Then
a1 = Format(a1, "0")
a2 = Format(a2, "0")
' for a3 to a9 in between
a10=format(a10,"0")

Else
a1 = Format(a1, "0." & String(dp, "0"))

' for all a2 to a9 in between

a10 = Format(a1,"0." & string(dp,"0"))

End If


thought it maybe possible to group all ten (or more) textboxes together?

hope this explains it better?

Bob Phillips
10-05-2007, 11:30 AM
What? No money? Why are you bothering us then?



For i = 1 To 10
If dp = 0 Then
Me.Controls("a" & i).Text = Format(a1, "0")
Else
Me.Controls("a" & i).Text = Format(a1, "0." & String(dp, "0"))
End If
Next i

northernstar
10-05-2007, 02:14 PM
xld

thanks very much for that will give it a go, not sure i fully understand it but will let you know how i get on

thanks again

northernstar
10-05-2007, 02:17 PM
so i am guessing that "a" is the first part of the name of the textbox and i is the end of the name

so i would be better off naming all of the textboxes in one group "a" and then a number upto what ever and adapting the code to suit

i think i get it now, what do you think?

thanks again

northernstar
10-05-2007, 02:21 PM
if i am getting this right then shouldnt the code be

For i = 1 To 10
If dp = 0 Then
Me.Controls("a" & i).Text = Format("a" & i, "0")
Else
Me.Controls("a" & i).Text = Format("a" & i, "0." & String(dp, "0"))
End If
Next i

northernstar
10-05-2007, 02:40 PM
this is not giving me what i need, tried what you suggested and also what i thought was right

i need textbox1 to be empty and formatted to a number of decimal places ready for the user to enter a figure, so with textbox2......textbox10, but the values entered into each text will be different but formatted then same

thanks in advance

northernstar
10-05-2007, 03:05 PM
joy playing around with the above code to get it working but no joy as yet will keep trying until i here from anyone who can suggest what i am do wrong

thanks

Bob Phillips
10-05-2007, 03:56 PM
I am not sure what your problem is. You said textboxes a1 to a10, which is what I tried to address.

The code I gave will, in one step, set the format of all 10, depending upon what is in dp, whatever that is.

northernstar
10-05-2007, 11:25 PM
sorry to disappoint you but it doesnt appear to work like that

i will double check my code and if i still have no joy i will post the a sample file with the code in it

thanks again

northernstar
10-05-2007, 11:37 PM
hi

i am still having problems with the code you sent me, so i have attached a sample file with the code and form

what i would like is

starting with a1 down to a6 i would like to enter 6 different numbers and then for them to be formatted to the number of decimal places stated in dp

at the moment the i enter the values in then press format and the 6 textboxes are formatted but with the value of a1, which is not what i want

any ideas

i think it is something to do with a1 being in the format bracket but i tried changed this to a & i and "a" & i but neither same to want to work

thanks again

northernstar
10-05-2007, 11:42 PM
just tried it again changing the a1 to a & i and it works fine now (tried it abt 50 times last night and it wouldnt work??)

thanks again!

Bob Phillips
10-06-2007, 12:39 AM
Ah I see, I missed changing the formatted item.

northernstar
10-06-2007, 05:43 AM
yes see we are all prone to mistakes

tahnks again

Bob Phillips
10-06-2007, 05:58 AM
Never claimed otherwise.

northernstar
10-06-2007, 06:25 AM
i was only messing around with you!! hahaha!!!

lucas
10-06-2007, 08:05 AM
Bob's just checking to see if your learning anything..:devil2:

northernstar
10-06-2007, 09:16 AM
i thought i was learning something but i implemented the code into to my actual file but it doesnt seem to want to work

i had to define 'i' and 'nominal' as variables as it came up with the message 'varible not defined' this solved that problem but now it comes up with an error unable to find object

Private Sub ContinueE449_Click()
Dim i As Integer
Dim nominal
'checks to see if E449 Controller has been selected

Application.ScreenUpdating = False

If EquipmentUsed = "E449" Then
MultiPage1.Pages("E449").Visible = True
MultiPage1.Pages("E346DWT").Visible = False
MultiPage1.Pages("JobDetails").Visible = False
NominalE449.Visible = True
UnitsE449.Visible = True
ScaleE449.Visible = True
AppliedE449.Visible = True
ReadingE449.Visible = True
ErrorE449.Visible = True
PassFailE449.Visible = True
TolerancesE449.Visible = True
E449ADJ = False

' sets the number of decimal places


If DecimalPlaces = "" Then
Exit Sub
End If

For i = 1 To 33
If DecimalPlaces = 0 Then
Me.Controls("nominal" & i).Text = Format(nominal & i, "0")
Else
Me.Controls("nominal" & i).Text = Format(nominal & i, "0." & String(DecimalPlaces, "0"))
End If
Next i


ElseIf EquipmentUsed = "E346" Then
MultiPage1.Pages("E346DWT").Visible = True
MultiPage1.Pages("JobDetails").Visible = False
CorrectionE346L = 1.000621
CorrectionE346H = 1.000663
End If
'checks the units and sets up the conversion factor

End Sub

northernstar
10-06-2007, 09:18 AM
forgot file