473,320 Members | 2,146 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

VB Code

5
I'm very, very new to VB. I need to insert a comma in between menu items and end the sentence with a period. The sentence may have two menu items or it may have 8. The following is all I can come up with - I would appreciate some direction:

For number = 0 To choicesListBox.Items.Count - 1
completeOrder = completeOrder & " " & choicesListBox.Items.Item(number)
Next number
Dec 8 '06 #1
9 2555
sashi
1,754 Expert 1GB
I'm very, very new to VB. I need to insert a comma in between menu items and end the sentence with a period. The sentence may have two menu items or it may have 8. The following is all I can come up with - I would appreciate some direction:

For number = 0 To choicesListBox.Items.Count - 1
completeOrder = completeOrder & " " & choicesListBox.Items.Item(number)
Next number
Hi Edna,

You need to provide us with more information in order to help you. You have just provided code segment for a "For Loop", there is nothing much can be done with the above code segment. Good luck & Take care.
Dec 8 '06 #2
edna
5
Hi Edna,

You need to provide us with more information in order to help you. You have just provided code segment for a "For Loop", there is nothing much can be done with the above code segment. Good luck & Take care.
Not sure what you mean that not enought information is provided. I've enclosed the entire code for the OrderButton

Expand|Select|Wrap|Line Numbers
  1. Dim completeOrder As String = ""
  2. Dim number As Integer
  3. Dim perItem As Integer
  4.  
  5.         For number = 0 To choicesListBox.Items.Count - 1
  6.             completeOrder = completeOrder & " " & choicesListBox.Items.Item(number)
  7.         Next number
  8.  
  9.         'Message Box displayed as a result of menu items chosen
  10.         If perItem = number Then
  11.             MessageBox.Show("Your bodacious burger will be PLAIN (no condiments)." _
  12.             & completeOrder, "Your burger", MessageBoxButtons.OK, MessageBoxIcon.Information)
  13.         Else
  14.             MessageBox.Show("Your bodacious burger will have" _
  15.             & completeOrder, "Your burger", MessageBoxButtons.OK, MessageBoxIcon.Information)
  16.  
  17.         End If
  18.  
Dec 8 '06 #3
sashi
1,754 Expert 1GB
Not sure what you mean that not enought information is provided. I've enclosed the entire code for the OrderButton

Expand|Select|Wrap|Line Numbers
  1. Dim completeOrder As String = ""
  2. Dim number As Integer
  3. Dim perItem As Integer
  4.  
  5.         For number = 0 To choicesListBox.Items.Count - 1
  6.             completeOrder = completeOrder & " " & choicesListBox.Items.Item(number)
  7.         Next number
  8.  
  9.         'Message Box displayed as a result of menu items chosen
  10.         If perItem = number Then
  11.             MessageBox.Show("Your bodacious burger will be PLAIN (no condiments)." _
  12.             & completeOrder, "Your burger", MessageBoxButtons.OK, MessageBoxIcon.Information)
  13.         Else
  14.             MessageBox.Show("Your bodacious burger will have" _
  15.             & completeOrder, "Your burger", MessageBoxButtons.OK, MessageBoxIcon.Information)
  16.  
  17.         End If
  18.  
Hi Edna,

Please clear my doubts. Where are the "Menu" items being displayed in the above code segment? Is it the "completeOrder" thing? Take care.
Dec 8 '06 #4
edna
5
Hi Edna,

Please clear my doubts. Where are the "Menu" items being displayed in the above code segment? Is it the "completeOrder" thing? Take care.
In a listbox. The entire menu items are in a checklistbox and when I click on the items wanted, they are transferred to a standard listbox. Is this helpful?
Dec 8 '06 #5
edna
5
Hi Edna,

Please clear my doubts. Where are the "Menu" items being displayed in the above code segment? Is it the "completeOrder" thing? Take care.
I re-read your question and the answer is Yes.
Dec 8 '06 #6
Killer42
8,435 Expert 8TB
I'm very, very new to VB. I need to insert a comma in between menu items and end the sentence with a period. The sentence may have two menu items or it may have 8. The following is all I can come up with - I would appreciate some direction:

For number = 0 To choicesListBox.Items.Count - 1
completeOrder = completeOrder & " " & choicesListBox.Items.Item(number)
Next number
Expand|Select|Wrap|Line Numbers
  1. Dim strItems As String
  2. With choicesListBox
  3. For number = 0 To .Items.Count - 1
  4.   strItems = strItems & IIF(strItems="", " ", ", ") & .Items.Item(number)
  5. Next
  6. End With
  7. completeOrder = completeOrder & strItems
  8.  
Hope this is some help.

I think your mention of menu items may have confused the other respondent - menu items have a particular meaning in VB terms. :)

Is this VB.Net? I tend to think in VB6 terms, so my code may need some slight translations. I'm thinking you're probably .Net due to the .Items.Item(number) property, which in VB6 would be .List(number). As far as I know, the With...End With syntax should still work the same, but if not, just put back the choicesListBox that I stripped off various properties to shorten the code.
Dec 10 '06 #7
aaryan
82
[quote]
hi edna,
you have mentioned check listbox. does that mean a check box. once you select the check box the items are all added on to the list box and from there the desired result shd be generated,is it?
if my understanding is correct, i cd suggest u one thing. don't get things too complicated. once you choose menu items in the check box, and you click a submit button, the message box can be made to produce the items you have selected. the code for which i will furnish below.


Private Sub Command1_Click()
strchoice = " "
If Check1.Value = 1 Then
strchoice = Check1.Caption
End If
If Check2.Value = 1 Then
strchoice = strchoice & "," & Check2.Caption
End If
If Check3.Value = 1 Then
strchoice = strchoice & "," & Check3.Caption & "."
End If
MsgBox "your choice is " & strchoice
End Sub


if it is not satisfying your requirement, restate your problem clearly. i will try to help u out.
Dec 11 '06 #8
Killer42
8,435 Expert 8TB
hi edna,
you have mentioned check listbox. does that mean a check box. once you select the check box the items are all added on to the list box and from there the desired result shd be generated,is it?
if my understanding is correct, i cd suggest u one thing. don't get things too complicated. once you choose menu items in the check box, and you click a submit button, the message box can be made to produce the items you have selected. the code for which i will furnish below.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command1_Click()
  2. strchoice = " "
  3. If Check1.Value = 1 Then
  4.   strchoice = Check1.Caption
  5. End If
  6. If Check2.Value = 1 Then
  7.   strchoice = strchoice & "," & Check2.Caption
  8. End If
  9. If Check3.Value = 1 Then
  10.   strchoice = strchoice & "," & Check3.Caption & "."
  11. End If
  12. MsgBox "your choice is " & strchoice
  13. End Sub
  14.  
if it is not satisfying your requirement, restate your problem clearly. i will try to help u out.
Hi aaryan,

Hope you don't mind my jumping in here, but I think I have some idea what edna meant. (I've also put [c o d e] tags around your code - this is kind of a standard, here at TheScripts, and often aids readability.)

My understanding is that there is a "checklistbox" (which I would guess to be the VB.Net equivalent of a VB6 listbox with Style = Checkbox). That is, a listbox which allows you to check/uncheck the items. Each item which is checked is copied to another, standard listbox (though I agree with you, for simplicity it might be better to skip that step).

Assuming this is correct, then while your idea is still valid (no need to copy to another list), the code is not correct. Actually, I think it would be most sensible to adapt the code I posted, to work on the selected items in the first listbox.

Incidentally, I believe there are a couple of bugs in your code
  • If the first checkbox is not selected, then the entries will start with a comma
  • If the last checkbox is not selected, the full stop will be left off the end.
  • Given that there could be at least 8 check boxes (according to the original post), it would make much more sense to use a control array and loop through them.
Sorry, I hope you don't mind my critiquing your code - I just can't help myself.
Dec 11 '06 #9
aaryan
82
Hi aaryan,

Hope you don't mind my jumping in here, but I think I have some idea what edna meant. (I've also put [c o d e] tags around your code - this is kind of a standard, here at TheScripts, and often aids readability.)

My understanding is that there is a "checklistbox" (which I would guess to be the VB.Net equivalent of a VB6 listbox with Style = Checkbox). That is, a listbox which allows you to check/uncheck the items. Each item which is checked is copied to another, standard listbox (though I agree with you, for simplicity it might be better to skip that step).

Assuming this is correct, then while your idea is still valid (no need to copy to another list), the code is not correct. Actually, I think it would be most sensible to adapt the code I posted, to work on the selected items in the first listbox.

Incidentally, I believe there are a couple of bugs in your code
  • If the first checkbox is not selected, then the entries will start with a comma
  • If the last checkbox is not selected, the full stop will be left off the end.
  • Given that there could be at least 8 check boxes (according to the original post), it would make much more sense to use a control array and loop through them.
Sorry, I hope you don't mind my critiquing your code - I just can't help myself.
hi killer42,
never mind. that's just my mistake. thanks for correcting me.
Dec 14 '06 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

51
by: Mudge | last post by:
Please, someone, tell me why OO in PHP is better than procedural.
9
by: bigoxygen | last post by:
Hi. I'm using a 3 tier FrontController Design for my web application right now. The problem is that I'm finding to have to duplicate a lot of code for similar functions; for example, listing...
4
by: jason | last post by:
Hello. Newbie on SQL and suffering through this. I have two tables created as such: drop table table1; go drop table table2; go
16
by: Dario de Judicibus | last post by:
I'm getting crazy. Look at this code: #include <string.h> #include <stdio.h> #include <iostream.h> using namespace std ; char ini_code = {0xFF, 0xFE} ; char line_sep = {0x20, 0x28} ;
109
by: Andrew Thompson | last post by:
It seems most people get there JS off web sites, which is entirely logical. But it is also a great pity since most of that code is of such poor quality. I was looking through the JS FAQ for any...
5
by: ED | last post by:
I currently have vba code that ranks employees based on their average job time ordered by their region, zone, and job code. I currently have vba code that will cycle through a query and ranks each...
0
by: Namratha Shah \(Nasha\) | last post by:
Hey Guys, Today we are going to look at Code Access Security. Code access security is a feature of .NET that manages code depending on its trust level. If the CLS trusts the code enough to...
18
by: Joe Fallon | last post by:
I have some complex logic which is fairly simply to build up into a string. I needed a way to Eval this string and return a Boolean result. This code works fine to achieve that goal. My...
37
by: Alan Silver | last post by:
Hello, Newbie here, so please forgive what is probably a basic question ... I see a lot of discussion about "code behind", which if I have understood correctly, means that the script code goes...
171
by: tshad | last post by:
I am just trying to decide whether to split my code and uses code behind. I did it with one of my pages and found it was quite a bit of trouble. I know that most people (and books and articles)...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.