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

Home Posts Topics Members FAQ

fix out of range exception

1 New Member
i keep getting out of range exception when i run my code in vb..
it says that
HslSubj = Struktur(PosKt - 1)
is out of range exception unhandled..
but if i delete that i get a new error, which is argument exception.. please help me fix it..
i put my whole code below..

Expand|Select|Wrap|Line Numbers
  1. Public Class FrMain
  2.     Public KDasar(0 To 9, 0 To 1) As String
  3.     Public Imbuh(0 To 4, 0 To 1) As String
  4.     Public Struktur(0 To 3) As String
  5.     Public DesStruktur(0 To 3) As String
  6.  
  7.     Private Class KataDasar
  8.         Private pVal As String, pValint As Integer
  9.         Public Property description() As String
  10.             Get
  11.                 Return pVal
  12.             End Get
  13.             Set(ByVal value As String)
  14.                 pVal = value
  15.             End Set
  16.         End Property
  17.         Public Property groupID() As Integer
  18.             Get
  19.                 Return pValint
  20.             End Get
  21.             Set(ByVal value As Integer)
  22.                 pValint = value
  23.             End Set
  24.         End Property
  25.     End Class
  26.  
  27.     Private Class StrukKalimat
  28.         Private pVal As String, pVal2 As Integer
  29.         Public Property teks() As String
  30.             Get
  31.                 Return pVal
  32.             End Get
  33.             Set(ByVal value As String)
  34.                 pVal = value
  35.             End Set
  36.         End Property
  37.         Public Property IDstring() As String
  38.             Get
  39.                 Return pVal2
  40.             End Get
  41.             Set(ByVal value As String)
  42.                 pVal2 = value
  43.             End Set
  44.         End Property
  45.     End Class
  46.  
  47.     Sub InisialisasiDB()
  48.         Imbuh(0, 0) = "men"
  49.         Imbuh(1, 0) = "kan"
  50.         Imbuh(2, 0) = "mem"
  51.         Imbuh(3, 0) = "di"
  52.         Imbuh(4, 0) = "ber"
  53.  
  54.         Imbuh(0, 1) = "0"
  55.         Imbuh(1, 1) = "1"
  56.         Imbuh(2, 1) = "0"
  57.         Imbuh(3, 1) = "0"
  58.         Imbuh(4, 1) = "0"
  59.  
  60.         KDasar(0, 0) = "dengar"
  61.         KDasar(1, 0) = "simpan"
  62.         KDasar(2, 0) = "belanja"
  63.         KDasar(3, 0) = "baca"
  64.  
  65.         KDasar(0, 1) = "1"
  66.         KDasar(1, 1) = "1"
  67.         KDasar(2, 1) = "1"
  68.         KDasar(3, 1) = "1"
  69.  
  70.         KDasar(4, 0) = "sekarang"
  71.         KDasar(5, 0) = "dipasar"
  72.         KDasar(6, 0) = "hariini"
  73.         KDasar(7, 0) = "dilemari"
  74.         KDasar(8, 0) = "siangini"
  75.  
  76.         KDasar(4, 1) = "3"
  77.         KDasar(5, 1) = "3"
  78.         KDasar(6, 1) = "3"
  79.         KDasar(7, 1) = "3"
  80.         KDasar(8, 1) = "3"
  81.  
  82.         KDasar(9, 0) = "mainan"
  83.         KDasar(9, 1) = "0"
  84.  
  85.         Struktur(0) = "Subyek"
  86.         Struktur(1) = "Predikat"
  87.         Struktur(2) = "Objek"
  88.         Struktur(3) = "Keterangan"
  89.  
  90.         DesStruktur(0) = "Subjek berupa kata benda (nomina)"
  91.         DesStruktur(1) = "Predikat berupa kata kerja (verba)"
  92.         DesStruktur(2) = "Objek berupa kata benda (nomina)"
  93.         DesStruktur(3) = "Keterangan berupa keterangan waktu atau tempat"
  94.  
  95.     End Sub
  96.  
  97.     Function StateMachine1(ByVal kal As String) As String
  98.         Dim HslString As String, HslKet As String, HslPred As String, HslSubj As String
  99.         Dim HslObjek As String, hslImbuhan As String
  100.         Dim pch() As String = Split(kal, " ")
  101.         Dim A As Integer, e As Integer = -1, u As Integer, k As Integer, PosKt As Integer
  102.         Dim PosKt1 As Integer
  103.  
  104.         For u = 0 To UBound(pch)
  105.             For A = 0 To UBound(Imbuh)
  106.                 e = InStr(1, pch(u), Imbuh(A, 0), CompareMethod.Text)
  107.                 If (e > 0) And (e < Len(pch(u)) - 3) Then
  108.                     If Imbuh(A, 1) = "0" Then hslImbuhan = hslImbuhan & Imbuh(A, 0) & "!"
  109.                 ElseIf e <> 0 Then
  110.                     If e = Len(pch(u)) - (Len(Imbuh(A, 0)) + 1) Then
  111.                         If Imbuh(A, 1) = "1" Then hslImbuhan = hslImbuhan & Imbuh(A, 0) & "!"
  112.                     End If
  113.                 End If
  114.             Next A
  115.         Next u
  116.  
  117.         For k = 1 To 2
  118.             For u = 0 To UBound(pch)
  119.                 For A = 0 To UBound(KDasar)
  120.                     e = InStr(1, pch(u), KDasar(A, 0), CompareMethod.Text)
  121.                     If e > 0 Then
  122.                         If KDasar(A, 1) = "3" Then
  123.                             HslKet = Struktur(CInt(KDasar(A, 1)))
  124.                             PosKt1 = u
  125.                         ElseIf KDasar(A, 1) = "1" Then
  126.                             HslPred = Struktur(CInt(KDasar(A, 1)))
  127.                             PosKt = u
  128.                         End If
  129.                     End If
  130.                 Next A
  131.             Next u
  132.         Next k
  133.  
  134. Lanjut:
  135.         If PosKt1 = 0 Then
  136.             PosKt = PosKt - 1
  137.         End If
  138.  
  139.         HslObjek = Struktur(PosKt + 1)
  140.         HslSubj = Struktur(PosKt - 1)
  141.         If PosKt1 = 0 Then
  142.             HslString = HslKet & "-" & HslSubj & "-" & HslPred & "-" & HslObjek & "#" & Mid(hslImbuhan, 1, Len(hslImbuhan) - 1)
  143.         Else
  144.             HslString = HslSubj & "-" & HslPred & "-" & HslObjek & "-" & HslKet & "#" & Mid(hslImbuhan, 1, Len(hslImbuhan) - 1)
  145.         End If
  146.         StateMachine1 = HslString
  147.     End Function
  148.  
  149.     Function BaseParsing(ByVal kt As String) As String
  150.         Dim A As Integer, e As Integer = 0
  151.         BaseParsing = kt
  152.         For A = 0 To UBound(KDasar)
  153.             e = InStr(1, kt, KDasar(A, 0), CompareMethod.Text)
  154.             If e > 0 Then
  155.                 BaseParsing = KDasar(A, 0)
  156.                 Exit For
  157.             End If
  158.         Next A
  159.     End Function
  160.  
  161.     Sub StateMachine2()
  162.         Dim Wparts() As String = Split(txinput.Text, " ")
  163.  
  164.         Dim state As Integer = 0
  165.         While True
  166.             '            command = next command
  167.             Select Case (state)
  168.                 Case 0
  169.                     If (Command.Equals("USER")) Then
  170.                         '                       username = argument;
  171.                         state = 1
  172.                     ElseIf (Command.Equals("QUIT")) Then
  173.                         state = 4
  174.                     Else
  175.                         Error ("Unknown: " + Command())
  176.                         '                      break()
  177.                     End If
  178.                 Case 1
  179.                     If (Command.Equals("PASS")) Then
  180.                         '                       If (valid(username, argument)) Then
  181.                         '                      state = 2
  182.                         '                  Else
  183.                         '                      Error ("Unauthorized")
  184.                         '                      state = 3
  185.                         '                   End If
  186.                     Else
  187.                         Error ("Unknown: " + Command())
  188.                         Exit While
  189.                     End If
  190.             End Select
  191.         End While
  192.     End Sub
  193.  
  194.     Public Class SingleObjClass
  195.         '    private  SingleObjClass obj = new SingleObjClass()
  196.         Private SingleObjClass()
  197.         '     public  SingleObjClass.getInstance()
  198.         '    return obj;
  199.     End Class
  200.  
  201.     Private Sub FrMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  202.         Call InisialisasiDB()
  203.         LS1A.Items.Clear()
  204.         LS1B.Items.Clear()
  205.         LS2.Items.Clear()
  206.     End Sub
  207.  
  208.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  209.         Dim tmpRes As String = StateMachine1(LCase(txinput.Text))
  210.         Dim chnk1() As String = Split(tmpRes, "#")
  211.         Dim chnk2() As String = Split(chnk1(0), "-")
  212.         Dim chnk3() As String = Split(chnk1(1), "!"), j As Integer
  213.  
  214.         Dim ptg() As String = Split(LCase(txinput.Text), " ")
  215.  
  216.         LS1A.Items.Clear()
  217.         LS1B.Items.Clear()
  218.         LS2.Items.Clear()
  219.  
  220.         For j = 0 To UBound(chnk2)
  221.             LS2.Items.Add(chnk2(j))
  222.         Next
  223.  
  224.         For j = 0 To UBound(chnk3)
  225.             LS1B.Items.Add(chnk3(j))
  226.         Next
  227.  
  228.         For j = 0 To UBound(ptg)
  229.             LS1A.Items.Add(BaseParsing(ptg(j)))
  230.         Next
  231.  
  232.     End Sub
  233.  
  234.     Private Sub LS2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LS2.SelectedIndexChanged
  235.         Dim j As Integer
  236.         For j = 0 To UBound(Struktur)
  237.             If LS2.Items(LS2.SelectedIndex) = Struktur(j) Then
  238.                 LSDP.Text = DesStruktur(j)
  239.                 Exit For
  240.             End If
  241.         Next j
  242.     End Sub
  243.  
  244.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  245.         txinput.Text = ""
  246.         LS1A.Items.Clear()
  247.         LS1B.Items.Clear()
  248.         LS2.Items.Clear()
  249.         LSDP.Clear()
  250.     End Sub
  251. End Class
please help me fix it..
thank you so much..
Nov 12 '11 #1
1 2267
Rabbit
12,516 Recognized Expert Moderator MVP
In your code, there exists the possibility that the index you're attempting to access goes outside the range of 0-3.
Nov 14 '11 #2

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

Similar topics

2
17528
by: smith flyers | last post by:
string thingword=" testing hmmm"; string firstLetter,restOfWord; foreach (string word in thingword.Split()) { Console.WriteLine(word); // if this only use for output and the rest in the block is commented, no error !!!
3
2803
by: Pengyu | last post by:
Whenever I call listView.RemoveAt(listView.Count-1), which remove the last item, I get an out of range exception. How to solve this problem? Thanks a lot, Pengyu.
0
1984
by: Bill Johnson | last post by:
I have a further question regarding an archive post at: http://groups-beta.google.com/group/microsoft.public.dotnet.languages.csharp/messages/fe7604b410b324e8,ab8f23349b8bf19d,d79c7c14342df130,34af0447073a6842 and the error message: System.ArgumentOutOfRangeException from System.Windows.Forms Specified argument was out of the range of valid values. Parameter name: '70' is not a valid value for 'displayIndex'.
4
3646
by: Brad | last post by:
Now I am encountering my second very strange problem. I will describe the first one later. But my current problem lies with trying to bind to a combobox: Try If clubID <> "" And txtYear.Text <> "" Then DsEvents1.Clear() daEventInfo.SelectCommand.Parameters(0).Value = clubID daEventInfo.SelectCommand.Parameters(1).Value = txtYear.Text daEventInfo.Fill(DsEvents1) ElseIf txtYear.Text = "" Then MsgBox("Event Year needs to be selected",...
2
2386
by: Henry J. | last post by:
Has anybody run into this index out range exception when opening and then closing a collectionEditor from within a PropertyGrid? I use PropertyGrid to edit configurations in my application. One of the fields is a collection. I can expand or collapse the collection in the PropertyGrid fine. However,if I open the CollectionEditor associated with the collection, do nothing, and just close it, I get an index out of range error. Note...
0
1108
by: Nick | last post by:
Hi people, I have a custom control combo box in a windows application that has a list of items to be displayed. there are currently 17 items that are bound to the table that acts as the data source for this combo. Now as this combo is an editable box, when I try to add a new item, at times, and ArgumentOutOfRangeException is raised. On debugging, this is raised whenevr I try to access the control using: Me.SelectedValue or any other...
5
7931
by: pcnerd | last post by:
I'm trying to create a program that plots randomly colored pixels on a bitmap & then displays the bitmap. When I run the program, I see the pixels being plotted down the left side of the form. When it gets to the bottom, the "Argument out of range exception" occurs. So, obviously the program starts. The Help tells me that the argument isn't within the range of values, but it doesn't explain how to fix the problem. So the Help doesn't help!...
1
4226
by: dedipya | last post by:
Environment W2003K with Oracle 10 client connected to oracle using oracle odp provider.orcle is on solaries machine. while filling the dataset .net is throughing the error "argument was out of the range of valid values". we are getting error when trying to fill the dataset with more than 16 columns. if any date column is avaible in retrivels then fill dataset method is throwing the bellow error. Parameter name: Year, Month, and Day...
7
5632
by: Pucca | last post by:
Hi: Below is the error I got from the 2 lines of code below. I don't understand why and how to correct it. The actionMenu.DropDownItems has 0 item in its collection at the time of the code. Thanks. An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll Additional information: Index was out of range. Must be non-negative and less than the size of the collection.
2
7269
by: GR M | last post by:
Hi, I was trying to add two quantities at different rows of same description i.e same product_name and same item_pack.1st I want to check the table if it contains the same description or not by comparing with the first record and so on. When found, I'll add up the quantities and then to delete that particular row (to avoid duplicate search). But when I delete the row the particular row, next time it throws an out of index exception. Below Is...
0
9722
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9603
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
10644
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...
0
9200
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7664
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
5550
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...
1
4334
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3863
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3015
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.