russell84 Posted September 23, 2008 Posted September 23, 2008 Hey guys in vb how do you create a list say "1, 2, 3, 4 & 5" and add them to a ComboBox??? also how do you set an image within a dialog box?? Quote
fixo Posted September 23, 2008 Posted September 23, 2008 Create form with 3 combo boxes named: ComboBox1, ComboBox2, ComboBox3 Here are 3 methods how to fill boxes Give that a try Private Sub UserForm_Initialize() Dim listArr1 As Variant ReDim listArr2(0 To 9) As Variant Dim i Dim util As Object Set util = ThisDrawing.Utility util.CreateTypedArray listArr1, vbInteger, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ' popup 1st combobox ComboBox1.List() = listArr1 ' display 1st item ComboBox1.ListIndex = 0 For i = 0 To 9 listArr2(i) = i + 1 Next ' popup 2nd combobox ComboBox2.List() = listArr2 ' display 1st item ComboBox2.ListIndex = 0 ' popup 3rd combobox For i = 0 To 9 ComboBox3.AddItem i + 1 Next ' display 1st item ComboBox3.ListIndex = 0 End Sub ~'J'~ Quote
russell84 Posted September 24, 2008 Author Posted September 24, 2008 Thanks fixo - worked a charm. So your the guy to hit up with VB questions then haha. Cheers mate Quote
rocheey Posted September 24, 2008 Posted September 24, 2008 Hey guys how do you set an image within a dialog box?? If you are speaking of VBA, and a *real* dialog box, (like the Common Dialog "File Open" Module code you see floating around) I dont see a way around doing this - because the dialog boxes are *modal*, which means your VBA code is essentially on hold until the dialog box closes. You wont be able to run any API calls to place an image in there ... (I havent tried it tho, by setting the parent hwnd of the window to 0, or the desktop) Easier to create your own dialog box, and set your image to a frame control. Then to dynamically change the image from code, use the LoadPicture method: Private Sub UserForm_Click() Frame1.Picture = LoadPicture("c:\windows\Coffee Bean.bmp") End Sub Quote
russell84 Posted September 26, 2008 Author Posted September 26, 2008 thanks mate. Hey guys one more - with combo boxes how to you make sure input is only digits?? No text is allowed?? and vica vera Quote
CmdrDuh Posted September 26, 2008 Posted September 26, 2008 something like this Private Sub comboBoxName_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger) Select Case KeyAscii Case Asc("0") To Asc("9") Case Else KeyAscii = 0 End Select End Sub Quote
russell84 Posted September 26, 2008 Author Posted September 26, 2008 ok thanks - do you do the same with textboxes too?? Because i've tried and i can't get it to work Quote
rocheey Posted September 26, 2008 Posted September 26, 2008 yes, it's the same as the code posted above - but you might also have to allow for decimal points, and negative symbols, so you may have to take an additional step, since you can't loop thru "consecutive" ascii characters. I build a string of "allowable" keys ("0123456789-.") for numeric only text boxes. This method can be used to filter any different styles of keys, btw.... ' ------------- snip ----------------------------- Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger) Dim AllowableChars As String, I As Integer AllowableChars = "0123456789+-." For I = 1 To Len(AllowableChars) If Asc(Mid$(AllowableChars, I, 1)) = KeyAscii Then Exit Sub Next I KeyAscii = 0 End Sub ' ------------- snip ----------------------------- Quote
russell84 Posted September 29, 2008 Author Posted September 29, 2008 thanks mate - works great. Cheers for your coding help guys. Quote
haizang Posted April 14, 2011 Posted April 14, 2011 Hi, how do I add one more box with text (red, white and blue)? Thanks Quote
haizang Posted April 14, 2011 Posted April 14, 2011 Hi, How do I add one more box with texts (red,white,blue)? Thanks Quote
gabrielbrdc Posted September 4, 2014 Posted September 4, 2014 anyone knows how to pick a list for combobox from a *.txt file? or even excel file. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.