Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.6k views
in Technique[技术] by (71.8m points)

variable value from variable name in VBA

I have code that works that is

With ClientForm
    If retainerFee <> .RetainerFeeTB.Value Then
        LabelLB.AddItem (.RetainerFeeLabel.Caption)
        BeforeLB.AddItem (retainerFee) 'variable Value
        AfterLB.AddItem (.RetainerFeeTB) 'Textbox.value
    End If
    If less250 <> .Less250TB.Value Then
        LabelLB.AddItem (.less250label.caption)
        BeforeLB.AddItem (less250) 'variable Value
        AfterLB.AddItem (.Less250TB) 'Textbox.value
   End If
end with

but I'd like to make it so I don't need to writer the code for every variable that needs to be called and this is what I have so far for that

With ClientForm
    For Each ctrl In .ClientMP.Pages(page).Controls
        If TypeName(ctrl) = "TextBox" Or TypeName(ctrl) = "ComboBox" Then
            variableName = Left(ctrl.Name, Len(ctrl.Name) - 2)
            variableValue = ??variableName??
            tBValue = ctrl.Value
            If tBValue <> variableValue Then
                labelName = variableName & "Label"
                labelCaption = .Controls(labelName).Caption
                LabelLB.AddItem (labelCaption)
                BeforeLB.AddItem (variableValue)
                AfterLB.AddItem (tBValue)
            End If
        End If
    Next
End with

I just don't know how to get the Variable Value


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...