Jump to content

Recommended Posts

Posted

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??

Posted

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'~

Posted

Thanks fixo - worked a charm.

 

So your the guy to hit up with VB questions then haha.

 

Cheers mate

Posted
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

Posted

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

Posted

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

Posted

ok thanks - do you do the same with textboxes too??

 

Because i've tried and i can't get it to work

Posted

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 -----------------------------

Posted

thanks mate - works great.

 

Cheers for your coding help guys.:D

  • 2 years later...
Posted

Hi, how do I add one more box with text (red, white and blue)?

 

Thanks

Posted

Hi, How do I add one more box with texts (red,white,blue)?

 

Thanks

  • 3 years later...
Posted

anyone knows how to pick a list for combobox from a *.txt file? or even excel file.

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...