DsgnrsTLZAdmin
01-14-2004, 01:38 AM
I need to know how to put info into a dropdown box i have created and put what the user selects from the list in a textbox i have made
|
||||
Visual Basic: dropdown menusDsgnrsTLZAdmin 01-14-2004, 01:38 AM I need to know how to put info into a dropdown box i have created and put what the user selects from the list in a textbox i have made sage45 01-14-2004, 07:34 AM Are you talking vbscript or VB??? Is the option list generated dynamically or known??? -sage- DsgnrsTLZAdmin 01-14-2004, 01:31 PM sorry for not making this clear. anyway this is vb not vbscript. Basicaly im making a html editor and im going to use drop down boxes to insert tags into a text box... scroots 01-14-2004, 06:37 PM you basically put it in the form onload part or anywhere you want to add the items. dropdownname.additem "boo" or dropdownname.additem boo you can also use the with statement with dropdownname .additem "h" .additem "g" .additem "e" .additem "4" .additem "o" end with scroots DsgnrsTLZAdmin 01-14-2004, 10:59 PM sorry i dont understand.....this is my first vb program and your gonna have to explain every detail..sorry mpicklesimer 01-14-2004, 11:44 PM Real quickly, your dropdown is referred to as a Combo box you add whatever you want it to display with the following code. Assume you named your combo box "cmbMyShortList": cmbMyShortList.AddItem "Books" cmbMyShortList.AddItem "Cars" cmbMyShortList.AddItem "Computers" Put this code somewhere in your Form_Load Handler. Then you would put something like this into your cmbMyShortList_Change event handler: txtMyFavorites = txtMyFavorites & cmbMyShortList.Text Now I don't know if that last part works quite right, but I do know that the first block of code works great. sage45 01-15-2004, 12:26 AM If however, you are generating a dynamic list as opposed to a static list, I would use the following: Option Explicit 'Global Variables Public Sub LoadCombo(Combo As ComboBox, FileSpec As String, Section As String) On Error GoTo Errors Dim strRet As String, strRetVal As String, lngBufLen As Long, lngRet As Long Combo.Clear Do lngBufLen = lngBufLen + 1024 strRet = String$(lngBufLen, vbNullChar) lngRet = GetPrivateProfileStringA(Section, vbNullString, "", strRet, lngBufLen, FileSpec) Loop Until lngRet < lngBufLen - 2 strRet = Left$(strRet, lngRet - 1) Dim strArray() As String strArray = Split(strRet, vbNullChar) For lngRet = 0 To UBound(strArray) Combo.AddItem strArray(lngRet) Next lngRet Combo.ListIndex = 0 Errors: If Err.Number <> 0 Then MsgBox ("Error #:" & Str(Err.Number) & Err.Description) Exit Sub End If End Sub LoadCombo cboList1, Path + "/tmp1.tmp", "INISection" Con to this is it uses a file... However, I have used it successfully where I have created and populated a file with the information dynamically then called the information into the combo box with the code above... HTH, -sage- DsgnrsTLZAdmin 01-15-2004, 01:30 AM ok lets start over here and ill explain every detail i want to be able to select an HTML code from a list in a combo box(Combo3) and it paste what you select from that combo box(Combo3) into a RichTextBox (rtfText) help me please, this is my first program. im gonna need more help after i get this worked out, thank you all very much. scroots 01-17-2004, 09:09 PM double click on the combo box and then pick onchange from the dropdown. enter the following rtfText=rtfText + Combo3 to add an item to the drop down, double click on the form and then pick onLod from the list in the code editor and then just add in Combo3.additem "Item1" Combo3.additem "Item2" Combo3.additem "Item3" Combo3.additem "Item4" scroots DsgnrsTLZAdmin 01-18-2004, 01:22 AM Thank you so much. It adds to the list but now theres a problem. compile error: Assignment To Constant not permitted. and it points me to... Private Sub Combo3_Change() rtfText = rtfText + Combo3 End Sub and highlights what i have underlined: Private Sub Combo3_Change() rtfText = rtfText + Combo3 End Sub sage45 01-18-2004, 02:22 AM The compiler is saying you can't assign the information to a Constant... A constant is just what it's name implies, Constant, not changing... Variables are allowed to be modified and changed through the process of the application... Try using: Dim rftText As String HTH, -sage- scroots 01-18-2004, 10:15 AM look in your code for Const rtfText as that is setting it as a constant wheras it doesn't need to be as its a textbox on a page and doesn't need to be declared. scroots DsgnrsTLZAdmin 01-18-2004, 01:50 PM i tried using: Dim rftText As String no errors, but it doesnt add what you select in the dropdown to the text box... i looked in my code for Const rtfText and didnt see that. Maybe I should point out my textbox and my combo boxes are on two seperate forms. what now? Thanks sage45 01-18-2004, 03:33 PM In that case then, on the form where your combo box resides, use this: frmname.rtfText = frmname.rtfText + Combo3 Where 'frmname' is the name of the form that rtfText is residing on... HTH, -sage- DsgnrsTLZAdmin 01-18-2004, 06:47 PM that still doesnt work :-\ thanks scroots 01-18-2004, 07:36 PM There is no need to declare the rich text box in your code as it is an element. so it can be reffered to by its name. scroots DsgnrsTLZAdmin 01-18-2004, 07:46 PM and what does that mean? scroots 01-18-2004, 07:53 PM that in your code you don't need the line: Dim rftText As String scroots DsgnrsTLZAdmin 01-18-2004, 07:59 PM ok thanks but what do i need to do to get this thing to work? scroots 01-18-2004, 08:59 PM if possible can you post your entire VB code so people can take a look. scroots DsgnrsTLZAdmin 01-18-2004, 09:00 PM Private Declare Function SendMessage Lib "User32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Any) As Long Const EM_UNDO = &HC7 Private Sub mnuViewNewWebBrowser_Click() Dim frmB As New frmBrowser frmB.StartingAddress = "" frmB.Show End Sub Private Sub Command1_Click() Dim frmC As New frmBrowser frmC.StartingAddress = "" frmC.Show End Sub Private Sub Image1_Click() Dim frmB As New frmBrowser frmB.StartingAddress = "" frmB.Show End Sub Private Sub mnuViewWebBrowser_Click() Dim frmB As New frmBrowser frmB.StartingAddress = "" frmB.Show End Sub Private Sub MDIForm_Load() Me.Left = GetSetting(App.Title, "Settings", "MainLeft", 1000) Me.Top = GetSetting(App.Title, "Settings", "MainTop", 1000) Me.Width = GetSetting(App.Title, "Settings", "MainWidth", 6500) Me.Height = GetSetting(App.Title, "Settings", "MainHeight", 6500) LoadNewDoc frmDocument.text = frmDocument.text + cmbbold cmbbuttons.AddItem "<input type='submit' name='' value='' />" cmbbuttons.AddItem "<input type='reset' name='' value='' />" cmbinput.AddItem "<input type='' name='' value='' size='' maxlength=''" cmbinput.AddItem "<input type='text' name='' size='' maxlength='' />" cmbinput.AddItem "<input type='password' name='' value='' size='' maxlength='' />" cmbinput.AddItem "<input type='hidden' name='' size='' maxlength='' />" cmbmain.AddItem "<form method='' action='' />" cmbmain.AddItem "</form>" cmbfontfamily.AddItem "<body font='' />" cmbsize.AddItem "<font size=' ' />" cmbcolor.AddItem "<font color='#' />" cmbproperties.AddItem "<u> </u>" cmbproperties.AddItem "<u>" cmbproperties.AddItem "</u>" cmbbold.AddItem "<b> </b>" cmbbold.AddItem "<b>" cmbbold.AddItem "</b>" cmbitalics.AddItem "<i> </i>" cmbitalics.AddItem "<i>" cmbitalics.AddItem "</i>" End Sub Private Sub LoadNewDoc() Static lDocumentCount As Long Dim frmD As frmDocument lDocumentCount = lDocumentCount + 1 Set frmD = New frmDocument frmD.Caption = "Document " & lDocumentCount frmD.Show End Sub Private Sub MDIForm_Unload(Cancel As Integer) If Me.WindowState <> vbMinimized Then SaveSetting App.Title, "Settings", "MainLeft", Me.Left SaveSetting App.Title, "Settings", "MainTop", Me.Top SaveSetting App.Title, "Settings", "MainWidth", Me.Width SaveSetting App.Title, "Settings", "MainHeight", Me.Height End If End Sub Private Sub tbToolBar_ButtonClick(ByVal Button As MSComctlLib.Button) On Error Resume Next Select Case Button.Key Case "New" LoadNewDoc Case "Open" mnuFileOpen_Click Case "Save" mnuFileSave_Click Case "Copy" mnuEditCopy_Click Case "Paste" mnuEditPaste_Click Case "Cut" mnuEditCut_Click Case "Undo" mnuEditUndo_Click End Select End Sub Private Sub mnuWindowTileVertical_Click() Me.Arrange vbTileVertical End Sub Private Sub mnuWindowTileHorizontal_Click() Me.Arrange vbTileHorizontal End Sub Private Sub mnuWindowCascade_Click() Me.Arrange vbCascade End Sub Private Sub mnuWindowNewWindow_Click() LoadNewDoc End Sub Private Sub mnuPreview_Click() Dim frmB As New frmBrowser frmB.StartingAddress = "" frmB.Show End Sub Private Sub mnuViewStatusBar_Click() mnuViewStatusBar.Checked = Not mnuViewStatusBar.Checked sbStatusBar.Visible = mnuViewStatusBar.Checked End Sub Private Sub mnuViewToolbar_Click() mnuViewToolbar.Checked = Not mnuViewToolbar.Checked tbToolBar.Visible = mnuViewToolbar.Checked End Sub Private Sub mnuEditPaste_Click() On Error Resume Next ActiveForm.text.SelRTF = Clipboard.GetText End Sub Private Sub mnuEditCopy_Click() On Error Resume Next Clipboard.SetText ActiveForm.rtfText.SelRTF End Sub Private Sub mnuEditCut_Click() On Error Resume Next Clipboard.SetText ActiveForm.rtfText.SelRTF ActiveForm.text.SelText = vbNullString End Sub Private Sub mnuEditUndo_Click() 'ToDo: Add 'mnuEditUndo_Click' code. MsgBox "Add 'mnuEditUndo_Click' code." End Sub Private Sub mnuFileExit_Click() 'unload the form Unload Me End Sub Private Sub mnuFilePrint_Click() On Error Resume Next If ActiveForm Is Nothing Then Exit Sub With dlgCommonDialog .DialogTitle = "Print" .CancelError = True .Flags = cdlPDReturnDC + cdlPDNoPageNums If ActiveForm.rtfText.SelLength = 0 Then .Flags = .Flags + cdlPDAllPages Else .Flags = .Flags + cdlPDSelection End If .ShowPrinter If Err <> MSComDlg.cdlCancel Then ActiveForm.text.SelPrint .hDC End If End With End Sub Private Sub mnuFileSaveAs_Click() Dim sFile As String If ActiveForm Is Nothing Then Exit Sub With dlgCommonDialog .DialogTitle = "Save As" .CancelError = False 'ToDo: set the flags and attributes of the common dialog control .Filter = "All Files (*.*)|*.*" .ShowSave If Len(.FileName) = 0 Then Exit Sub End If sFile = .FileName End With ActiveForm.Caption = sFile ActiveForm.text.SaveFile sFile End Sub Private Sub mnuFileSave_Click() Dim sFile As String If Left$(ActiveForm.Caption, 8) = "Document" Then With dlgCommonDialog .DialogTitle = "Save" .CancelError = False 'ToDo: set the flags and attributes of the common dialog control .Filter = "All Files (*.*)|*.*" .ShowSave If Len(.FileName) = 0 Then Exit Sub End If sFile = .FileName End With ActiveForm.text.SaveFile sFile Else sFile = ActiveForm.Caption ActiveForm.text.SaveFile sFile End If End Sub Private Sub mnuFileOpen_Click() Dim sFile As String If ActiveForm Is Nothing Then LoadNewDoc With dlgCommonDialog .DialogTitle = "Open" .CancelError = False 'ToDo: set the flags and attributes of the common dialog control .Filter = "All Files (*.*)|*.*" .ShowOpen If Len(.FileName) = 0 Then Exit Sub End If sFile = .FileName End With ActiveForm.text.LoadFile sFile ActiveForm.Caption = sFile End Sub Private Sub mnuFileNew_Click() LoadNewDoc End Sub |
| |||
EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum