473,811 Members | 2,756 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Error Code and how to get it to disappear

11 New Member
Here is the code again and the error I get is Invalid Argument=Value of "-1" is not valid for 'index' Parameter Name:index

Please advise the code so this error goes away and the program will still execute correctly. Other suggestions posted either still give errors or the program does not execute once I put the suggestion in. Thanks for your help.
Jo Ann


Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load

'load the item into the combobox
Try

vinStreamreader = New StreamReader("c ar.txt")
DisplayRecord()
Catch ex As Exception
'File is not found.
MessageBox.Show (ex.Message)
End Try


End Sub
Private Sub ComboBox1_Selec tedIndexChanged (ByVal sender As System.Object, ByVal e As System.EventArg s) Handles ComboBox1.Selec tedIndexChanged
'Read the next record.

DisplayRecord()
End Sub

Private Sub DisplayRecord()
'Read and display the next record.
Dim vinString As String
Do While vinStreamreader .Peek <> -1
vinString = vinStreamreader .ReadLine()
Me.ComboBox1.Te xt = vinString
Me.ComboBox1.It ems.Add(ComboBo x1.Text)


Me.ListBox1.Ite ms.Add(vinStrea mreader.ReadLin e())
Me.ListBox2.Ite ms.Add(vinStrea mreader.ReadLin e())
Me.ListBox3.Ite ms.Add(vinStrea mreader.ReadLin e())

Loop
'Display labels
Me.Label4.Text = Me.ListBox1.Ite ms(Me.ComboBox1 .SelectedIndex)
Me.Label5.Text = Me.ListBox2.Ite ms(Me.ComboBox1 .SelectedIndex)
Me.Label6.Text = Me.ListBox3.Ite ms(Me.ComboBox1 .SelectedIndex)
End Sub


End Class
Nov 26 '07 #1
3 1173
kadghar
1,295 Recognized Expert Top Contributor
Here is the code again and the error I get is Invalid Argument=Value of "-1" is not valid for 'index' Parameter Name:index

...
When the combobox has no selected item, its index is -1.
I think this problem can be solved by changing Me.Combobox1.Se lectedIndex with an integer, lets say K, and :

Expand|Select|Wrap|Line Numbers
  1. dim K as integer
  2. K= me.combobox1.selectedindex
  3. if K<0 then K = 0
This way, if there's no item selected, it'll use the first of the list. Or you can just exit the sub if the index is -1.

HTH
Nov 26 '07 #2
pooker75
11 New Member
I tried this code at the very beginning and at each sub and I still get the message. Good idea but does not eliminate the error. Jo Ann
Nov 26 '07 #3
kadghar
1,295 Recognized Expert Top Contributor
I tried this code at the very beginning and at each sub and I still get the message. Good idea but does not eliminate the error. Jo Ann
could you put again your code, but with code tags, so it'll numerate the lines, and tell us in what line does the error first appear??

Thanks =)
Nov 26 '07 #4

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

Similar topics

11
10530
by: varois83 | last post by:
Hi I am in the process of creating a guestbook for my site, I am a newbie and used several tutorials and customized them to what I need using the little knowledge I got. I get the following error in my code: Notice: Undefined variable: stars in c:\program files\easyphp1-7\www\guestbook\add.php on line 60
1
1762
by: Bil Click | last post by:
I am coding classic ASP pages in Visual Studio .Net 2003. I have a file called counties_option.asp that just has a list of options: <OPTION VALUE="030">ANSON</OPTION> <OPTION VALUE="040">ASHE</OPTION> etc... I then call this as an include file in several places in a file called page1.asp like this:
4
1602
by: jmensch | last post by:
I'm reasonably new to JavaScript and DHTML, so I'm sorry if this is an obvious mistake. The following snippet of code is intended to make the menu -- the absolute-positioned <div> section -- disappear when one mouses over the graphic, but instead it generates a "document. menu_admin has no properties" error in Firefox and does nothing in IE. Can someone tell me what it is that I'm doing wrong here?
6
4766
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much appreciated. Thanks in advance
10
3769
by: robert d via AccessMonster.com | last post by:
I have a global error handler that up until today has been working flawlessly. Let me first provide the relevant code **************************************************************** On Error GoTo Err_Ctrl 'This code is generating the error If Nz(Me.SubformCont.Form!txtUsage,"") = "' Then Msg "There's a problem"
3
1563
by: hyd | last post by:
Hello, I use VS2005 - C++/CLI. I have some kind of events in native C++. I want to raise .NET events when my native C++ events occur. So, I wrote some code for that but I have an C1001 error (An internal error has occurred in the compiler). Below, a piece of code that produces the same error : ***** CLR - Class Library project *****
2
1636
by: nickyeng | last post by:
I have a class, and i try to create an object of it but it give me error in compilation. The error is something like "]b]undefined reference to 'Game::PowerUp::powerups", in constructor of Game::PowerUp. The error also contain another 2 error : also are undefined reference but under ~PowerUp destructor. it compiled well actually if i dont create an object of it in test.cpp(main program to create objects), but once i coded this "PowerUp*...
15
16079
by: Dave | last post by:
I am getting the error above intermittantly with an ASP 3.0 page using an MS Access 2003 database. I have searched Google extensively and found the following possible causes for this error: A field name was spelled incorrectly. One or more of the values was blank. You tried to insert the wrong datatype (e.g. surrounded a numeric value with quotes, or forgot to put quotes around a string).
3
3272
by: rorni | last post by:
Hi, I'm porting code from Windows to HP-UX 11, compiling with g++. I'm getting a compilation error on the system's debug.h include file, which is included very indirectly through a series of other system include files. The one I am including is <map> . The errors I am getting are: /opt/hp-gcc-4.2.1/lib/gcc/ia64-hp-hpux11.23/4.2.1/../../../../include/c++/4.2.1/debug/debug.h: At global scope:...
9
3209
by: ahilar12 | last post by:
1. <head> 2. <script type="text/javascript"> 3. </script> 4. </head> 5. <body> 6. <form> 7. <select name="team" id="mylist" > 8. <option></option> 9. <option>north</option> 10. <option>south</option>
0
9607
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10663
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10416
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10138
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7676
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6897
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5567
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3881
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3029
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.