combobox (dropdownlist ver) issue.......vb6

  • (4 Pages)
  • +
  • 1
  • 2
  • 3
  • Last »

45 Replies - 17109 Views - Last Post: 31 May 2011 - 07:24 AM Rate Topic: -----

#1 gruffy  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 106
  • Joined: 28-April 11

combobox (dropdownlist ver) issue.......vb6

Posted 10 May 2011 - 03:47 AM

Hi all and thanks for reading, my problem comes from finding the right approach to create a runtime scenario where a combobox(2- dropdownlist) choice denotes whether a series of further comboboxes are enabled or not.

(NOTE: WHERE "1 OR 2" IS IN THE CODE I HAVE TRIED STATING THE ACTUAL STRINGS AS VALIDATAION TOO, BUT DID NOT WORK EITHER....)
my code so far is.....

If cboCat.Change = 1 or 2 then 

   cboDept.Enabled = True ' changes from set to enabled = false
   cboFee.Enabled = True    ' changes from set to enabled = false
   cboPaid.Enabled = True    ' changes from set to enabled = false
End If





Please help people im a newb and dont know very much about vb6, just that its suppoesed to work and i cant get it too :(
Thankf fr reading

Is This A Good Question/Topic? 0
  • +

Replies To: combobox (dropdownlist ver) issue.......vb6

#2 Ionut  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 385
  • View blog
  • Posts: 1,057
  • Joined: 17-July 10

Re: combobox (dropdownlist ver) issue.......vb6

Posted 10 May 2011 - 06:14 AM

If cboCat.Text = "1" or cboCat.Text = "2" then 


Was This Post Helpful? 1
  • +
  • -

#3 gruffy  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 106
  • Joined: 28-April 11

Re: combobox (dropdownlist ver) issue.......vb6

Posted 10 May 2011 - 06:43 AM

hi and thanks for reply, this hasnt worked so maybe i wasnt clear enough in my explanation..

1. i have (eg) two comboboxes
2. i want the second combobox to highlight and be available to the user for selection upon choosing a text value forund in the first combobox.
3. if the first combobox value does not equal the required value to highlight and enable combobox 2, then cmbobox 2 should stay greyed out and unusable etc

It would seem i have looked everywhere for a simple explanantion on this and i seem only to comeup with nothing that works, my comboboxes are set to 2-dropdownlist in the style tab of properties, has this gt anything to do with how i approach the code to control what i need to happen.
Sorry for being a newbie know nothing, but its coupled with trying to fit in simultaneous programming language learning all at once due to uni course and although see the similarities in all languages, am striggling with syntax and method of instantiation/declaration etc
sorry , again , for bieng newbie and asking pityful question, that probably seems trivial and simple to the rest of the world

Gruffy
Was This Post Helpful? 0
  • +
  • -

#4 Ionut  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 385
  • View blog
  • Posts: 1,057
  • Joined: 17-July 10

Re: combobox (dropdownlist ver) issue.......vb6

Posted 10 May 2011 - 10:27 AM

No need to apologize, you are here to help you.
Let's take it by steps.
1. 2 comboboxes(e.g.) - combo1 and combo2, I will name them, combo2.Enabled = false
2 -3. You have to check the value user selected. The easiest way is to check the Text or Value property of the comboBox control
if combo1.Text = Value then 
   combo2.Enabled = true
end if


if there are more options that will enable combo2, use or operator
if combo1.Text = value1 or combo2.Text = value2 then 
   combo2.Enabled = true
end if 


If you want to check the index of the selected item . let's say you have in combo apple, mango and banana. If you want to enable combo2 only when apple is selected then
if Combo1.ListIndex = 0 then ' this means apple. ListIndex is zero-based
   combo2.Enabled = 0
end if 


For more items(select mango or banana)
if combo1.ListIndex = 1 or combo1.ListIndex=2 then 
   combo2.Enabled = true
end if 


Was This Post Helpful? 1
  • +
  • -

#5 gruffy  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 106
  • Joined: 28-April 11

Re: combobox (dropdownlist ver) issue.......vb6

Posted 10 May 2011 - 12:16 PM

tHis is truly amazing and thankyou for such a quick reply ionut, It has gvenme a much better insight to the correct way to carry this out and it works beautifully, so tankyou so amazingly much i cant tell you:)
.....In addition to this, if i may be so bold or to anybody else who can answer......Could you direct me how to ensure that when a user decides to rechoose a selection in the combo1 box that the others re fade or is that another if statement in a combo1 lost focus event.
Im not sure, but anyway thankyou so much for orignal post ionut, like is say this has helped me no end already ...thankyou thankyou , thankyou :) :bananaman: <--YO

sorry to ask that really, think i have sorted it in a ese clause to the if statement, hopefu;;y now i can mkae this functionality apply to the other combo boxes i have associated to the main one .
Thank agaiin IOnut
Gruffy
Was This Post Helpful? 0
  • +
  • -

#6 Ionut  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 385
  • View blog
  • Posts: 1,057
  • Joined: 17-July 10

Re: combobox (dropdownlist ver) issue.......vb6

Posted 10 May 2011 - 12:28 PM

You're welcome.

For the new question. This would be an else to the if.
E.g. If choose first banana(ListIndex = 2), combo2 will enable. If you don't want banana(and was mistaken selected), then combo2 should be disabled.
if combo1.ListIndex = 2 then 
   combo2.Enabled = True
'here you can add some elseif's 
'elseif combo1.ListIndex = 1 then 
'   combo3.Enabled = True
'   combo2.Enabled = False -- if you put this elseif the big else(else from the first if) 
                             'won't be   reached anymore, so you have to do all the work here.
                             'Now, depends on what event you chose to implement(I think would  be
                             'Click event). Maybe the logic will not need an elseif. 
else
   Combo2.Enabled = False
end if 


Was This Post Helpful? 1
  • +
  • -

#7 gruffy  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 106
  • Joined: 28-April 11

Re: combobox (dropdownlist ver) issue.......vb6

Posted 10 May 2011 - 12:46 PM

Thanks again IOnut , i managed to sort it thanks, but it still leaves selection the combobox that has been reblanked after the reselect.

I have tried adding into the else bit before the
combo2.enabled = false
bit of code
elow is some of thing i have tried ...

combo2.Text = -1

and
combo2.Text = "            "

^ to try and crete a blank set of spaces^
and
combo2.Text = Empty

and
combo2.Text = Null



and a some others et no avail, but am worried i am not correctly instantiating the statement or something like that :withstupid:
Nyway thanks for all your help so far , tis truly gold dust advice and i cant thank you enough
IOnut
Was This Post Helpful? 0
  • +
  • -

#8 Ionut  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 385
  • View blog
  • Posts: 1,057
  • Joined: 17-July 10

Re: combobox (dropdownlist ver) issue.......vb6

Posted 10 May 2011 - 12:55 PM

.Text property is a string so this
combo2.Text = -1


is not correct. And instead of Empty and Null and the set of spaces use either
""(which is a null string or vbNullString(which is equivalent to "", but more elegant in the matter of writing the code).

On the other hand, ListIndex property is an integer. So a valid assignment for resetting combo2 would be
combo2.ListIndex = -1


Was This Post Helpful? 1
  • +
  • -

#9 gruffy  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 106
  • Joined: 28-April 11

Re: combobox (dropdownlist ver) issue.......vb6

Posted 10 May 2011 - 01:50 PM

Hey thanks IOnut, below is the final devved code i have created with all your help, i completed this with just your original helpful post in the end (that was super helpful, and then i found a problem and quickly posted it on here but was solving them almost as soon as i posted them..... This has made me quite proud that i am finally getting certain aspects of vb)...and alot of that has been down to you my man , thanks and thank again forever.

final code below for anyone who might need it and attached is proj for you to have a look at ionut if you like
(my next step is to create a text file read,write and append system to accompany the text fields in th form )
Any advice would be ever so much appreciated as i love ya teaching stylee IOnut, very succint, very clean and clear (optimal, as they say)
...as mentioned code below
Private Sub cboCat_Click()
'This bit of code cerates an instant validation over the list boxes
'due to the student options wiping out access to the other boxes

If cboCat.ListIndex = 0 Or cboCat.ListIndex = 1 Then 'This ensures the other boxes are greyed out until the correct one selected
    cboDept.Enabled = True 'make combobox "dept" open to use
    cboFee.Enabled = True   'make combobox "dept" open to use
    cboPaid.Enabled = True   'make combobox "dept" open to use
Else:
      cboDept.ListIndex = -1  'make combobox "dept" equal to -1 (show nothing in box)
      cboFee.ListIndex = 0    'make combobox "Fee" equal to  0(shows FREE)
      cboPaid.ListIndex = 2   'make combobox "paid" equal to  3(shows N/A)
      cboDept.Enabled = False   'make combobox "dept" closed to use
      cboFee.Enabled = False    'make combobox "Fee" closed to use
      cboPaid.Enabled = False   'make combobox "Paid" closed to use

    End If
    
End Sub
'**********************************************************************************

Private Sub Form_Load()
cboFee.Enabled = False

    cboDept.Enabled = False

'Populate the Category combolistboxes in frmMain Form
	cboCat.AddItem "Staff- Ordinary"
	cboCat.AddItem "Staff- Car Share"
	cboCat.AddItem "Student "
	cboCat.AddItem "Student- Disabled"
	
'Populate the department combolistbox in frmMain Form
	cboDept.AddItem "Drama & Performing Arts"
	cboDept.AddItem "Sciences"
	cboDept.AddItem "Modern Languages"
	cboDept.AddItem "Leisure & Sport"
	cboDept.AddItem "Hospitality & Catering"
	cboDept.AddItem "Technology"
	cboDept.AddItem "Mechanical engineering"
	cboDept.AddItem "Animal Health Care"
	cboDept.AddItem "Business & Computing"
	cboDept.AddItem "Public Services"
	
'Populate the Fee combolistbox in frmMain Frm
	cboFee.AddItem "FREE"
	cboFee.AddItem "10.00"
	cboFee.AddItem "15.00"
	
'Populate the Paid combolistbox in frmMain Frm
	cboPaid.AddItem "NO"
	cboPaid.AddItem "YES"
	cboPaid.AddItem "N/A"

End Sub

' save button for the entry form
Private Sub cmdSaveAll_Click()
' not coded yet, gotta learn this properly tonnight unless you wanna help matey :)/>

End Sub



here is project so far (dropdown boxes fully working )

here is project so far (dropdown boxes fully working )

Attached File(s)


Was This Post Helpful? 0
  • +
  • -

#10 Ionut  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 385
  • View blog
  • Posts: 1,057
  • Joined: 17-July 10

Re: combobox (dropdownlist ver) issue.......vb6

Posted 10 May 2011 - 02:04 PM

Don't mention it, mate. Glad I could help you and every issue is clear and solved.

2 things I will say next:
1. I have no idea what do you want to do on cmdSaveAll_Click event. Save them where? to other variables? a class? a text file? a binary file?
2. Working with files : D.I.C. has two sections dedicated to examples and learning:Tutorial and Snippet. From there I give you something to look over:
Read from a file
Save to file
For append, use the word append instead of input(you will figure it out what I want to say after you read the above two tutorials)
Was This Post Helpful? 1
  • +
  • -

#11 gruffy  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 106
  • Joined: 28-April 11

Re: combobox (dropdownlist ver) issue.......vb6

Posted 10 May 2011 - 02:40 PM

Thanks Ionut amazing help again
I have just hit a new wall though, due to me transferring the above code and the frame holding all the combos etc into another projects form.
It doesnt seem to work, weird, im thinking.
Have declared it in the sub form_load section and instantiated the
Option Explicit
declaration and have tried with that too, stuped a little :withstupid:
Is there something here my small brain doesnt get again ? :helpsmilie:
willkeep trying though... :donatello:

with regards to being clearer over file requirements-
the file system should handle:
(a)text file creation from data in the form
(B)editing of file (append)
©deletion of files
(d)Saving the file
(e)Reopening/manipulation of file to print/display formatted results
(the last one also has to be able to be filtered, i have chosen some checkboxes and was goingto try and code them to filter down the resulting choices for printing out to screen or printer)
I hope that goes in some small way towards clarifying what i was trying to get across in my last post.
Thanks ever so much IOnut for everything, it would seem you have saved my proverbial bacon due to your expert skills of teaching the newb
PS Thanks for those links they are sure to help me on the quest to create a file system...., could u tell me ifyou think it might be better to create a class module for the file functions or is that out of my reach right now and ishould just stick to in form coding.
cheers again matey.
Gruffy
Was This Post Helpful? 0
  • +
  • -

#12 gruffy  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 106
  • Joined: 28-April 11

Re: combobox (dropdownlist ver) issue.......vb6

Posted 10 May 2011 - 02:56 PM

scrap that about the frame of combos not working , have sorted it somehow, i have type something and it has it working now, im losing it i think, too little sleep or something lol.
seems learning to code put sleeping right down there on the priorities list when you have a conundrum :offtopic:

Anyway any help and guidance relating to the rest of my last post would be amazing , thanks once again for you r patience IOnut, you`re a BEAST of aceness
gruffy

scrap that about the frame of combos not working , have sorted it somehow, i have type something and it has it working now, im losing it i think, too little sleep or something lol.
seems learning to code put sleeping right down there on the priorities list when you have a conundrum :offtopic:

Anyway any help and guidance relating to the rest of my last post would be amazing , thanks once again for you r patience IOnut, you`re a BEAST of aceness
gruffy
Was This Post Helpful? 1
  • +
  • -

#13 Ionut  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 385
  • View blog
  • Posts: 1,057
  • Joined: 17-July 10

Re: combobox (dropdownlist ver) issue.......vb6

Posted 10 May 2011 - 03:15 PM

Quote

scrap that about the frame of combos not working , have sorted it somehow, i have type something and it has it working now

This should not happen :) In programming/development there isn't voodoo or something alike. You should take a look again over the project(maybe tomorrow after you get to rest) and see what went wrong. Try doing n new projects until you see what went wrong. But, kudos because you didn't wait for a response and tried to solve by yourself.

Filesystem
a)On cmdSaveAll_click event will go some code from writing to a file. The writing method also creates the file if doesn't exists.
b ) editing - I let you figure it out
c ) deletion - In tutorial section there is(if I saw well) a topic that covers this part(there are 2 pages of tutorials in Visual Basic subsection, so will not be hard to find it). Anyway, this can be achived with Dir and kill functions(inside a do while) - maybe you google them and build yourself the deletion method :)
d) saving the file - covered
e) reading - covered above. Plus depending on the size of the data, you can use collections
This file system thing should be made having a format in mind(maybe XML, maybe INI, maybe something you think about) Because you may want to store different sections and you have to identifiy them. First, go with the simple method. 5 values separated by space, tab, end of line etc. Then think further, smarter.
In this topic, also I would suggest you to look over FileSystemObject(good to know and easy to use)

Regarding the new class module, I suggest you to work in the easiest way possible for you, BUT dividing your code in many class modules(every module doing something specific) is the best way to go. Your code is organized and you know where to find a specific function(you don't loose time searching in it in thousands of lines of code).
Was This Post Helpful? 1
  • +
  • -

#14 gruffy  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 106
  • Joined: 28-April 11

Re: combobox (dropdownlist ver) issue.......vb6

Posted 10 May 2011 - 03:38 PM

Graciously i thank you for your wise word IOnut, today you ar emy hero , i am gonna look into coding file system in the next hour or so and am about to lok over the curent set of links you have provided me with .
Thanx again boss man,


Begin VB.Form frmMain 
   Caption         =   "Form1"
   ClientHeight    =   4620
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   5460
   LinkTopic       =   "Form1"
   ScaleHeight     =   4620
   ScaleWidth      =   5460
   StartUpPosition =   3  'Windows Default

Begin VB.CommandButton cmdIOnut 
         Caption         =   "Click ME"
         Height          =   375
         Left            =   3480
         TabIndex        =   8
         Top             =   2160
         Width           =   1575
      End

Private Sub cmdIOnut_onclick()

MsgBox = "You R the Bestest, thanks IOnut. Gruffy"

End Sub  


Gruffy :bananaman:

Quote

Happily coding along in his own little microcosm

Was This Post Helpful? 0
  • +
  • -

#15 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: combobox (dropdownlist ver) issue.......vb6

Posted 11 May 2011 - 03:56 PM

As regards this code:
Private Sub cboCat_Click()If cboCat.ListIndex = 0 Or cboCat.ListIndex = 1 Then 'This ensures the other boxes are greyed out until the correct one selected
    cboDept.Enabled = True 'make combobox "dept" open to use
    cboFee.Enabled = True   'make combobox "dept" open to use
    cboPaid.Enabled = True   'make combobox "dept" open to use
Else:
      cboDept.ListIndex = -1  'make combobox "dept" equal to -1 (show nothing in box)
      cboFee.ListIndex = 0    'make combobox "Fee" equal to  0(shows FREE)
      cboPaid.ListIndex = 2   'make combobox "paid" equal to  3(shows N/A)
      cboDept.Enabled = False   'make combobox "dept" closed to use
      cboFee.Enabled = False    'make combobox "Fee" closed to use
      cboPaid.Enabled = False   'make combobox "Paid" closed to use

    End If
    
End Sub
It can be rendered more concisely thus:
Private Sub cboCat_Click()
With cboCat
    cboDept.Enabled = .ListIndex <= 1
    cboFee.Enabled = .ListIndex <= 1
    cboPaid.Enabled = .ListIndex <= 1
    If .ListIndex > 1 Then
        cboDept.ListIndex = -1  'make combobox "dept" equal to -1 (show nothing in box)
        cboFee.ListIndex = 0    'make combobox "Fee" equal to  0(shows FREE)
        cboPaid.ListIndex = 2   'make combobox "paid" equal to  3(shows N/A)
    End If
End With
 End Sub

This post has been edited by BobRodes: 11 May 2011 - 03:58 PM

Was This Post Helpful? 1
  • +
  • -

  • (4 Pages)
  • +
  • 1
  • 2
  • 3
  • Last »