Error While Coding!!

I am following a book's direction to code, but when i entered this startment

' For intForLoopCtr = 1 To CInt (txtNoPics.Text) ' <<<<<<<< then it said 'intForLoopCtr" is not decared.......

so anyone have any idea to make it decleared



Answer this question

Error While Coding!!

  • mickyjtwin

    but i dun get where i can find the objectype

    jux like this code

    "intRndNo = _"   how do i know which objecttype is that


  • DPotages

    HelpMePI0x,
    you have to declare every object you are using, because Windows has to reserve space in the computers memory.
    Make sure you declare variables before you start using them!

    To declare an object, type this:
    dim 'objectname' as 'objecttype'
    for example (using your code):
    dim intForLoopCtr as Integer
    dim blnFullSetComplete as boolean

    Complete code (as far as given):

    dim intForLoopCtr as Integer
    dim blnFullSetComplete as Boolean = False
    For intForLoopCtr= 1 To CInt(txtNoPics.Text)
    Do until blnFullSetComplete = True
    ' code here
    Loop
    Next intForLoopCtr

    Grtz, Tom.



  • FallenKing

    You've got two options... either create intForLoopCtr before your loop starts or within...

    To do so before hand you'd:

    Dim intForLoopCtr As Integer
    For intForLoopCtr = 1 To CInt(txtNoPics.Text)

    Otherwise you would do so within the loop ala:

    For intForLoopCtr As Integer = 1 To CInt(txtNoPics.Text)

    Does this work for you



  • Rollin

    You need to be a bit more descriptive in what you telling us. And provide us with sufficient code to see what you are doing.

    This code could be either - just a string containing some code if the quotes are part of the actual line,

    or

    FormatNumber (CInt((txtNoRange.text * Rnd()) +1))

    If the quotes are not part of the actual line then

    A call to a Sub called FormatNumber which probably you are showing as incorrect as it should probably be Cint instead of Int. And is depending upon implicit type conversion to convert a textbox text property. So you almost certainly do not have Option Strict On. This will fail if the contents of the textbox are not convertable to a number - ie. enter value "a" in the textbox.


    intRndNo = FormatNumber (CInt((txtNoRange.text * Rnd()) +1))

    or

    intRndNo = _
    FormatNumber (CInt((txtNoRange.text * Rnd()) +1))

    if you use the line contintuation character _ do not put any blank lines between the end of the first line indicated by the _ and the start of the next line ie. FormatNumber......

    All the _ does is allow a long line to be displayed on multiple lines to make reading the statement easier.


  • xavito

    Always have Option Explicit On!

    Oh, and BTW, as spotty says, I would very very strongly recommend that you have it on. I believe this is written on the Big Stick of Recommendatons.

    Another common coding technique is to use short variable names for loop variables: usually i, j and k are very common ones: whatever book you are reading I'd say get rid of it and find another one, if that/those line(s) of code came from the book.



  • Drake1500

    Having the safety net of option explicit On results in you able to catch any typo errors for declared variables.

    So if you declare it and then when you use it you mistype the variable name then it will result in the error and hence you trace it back to what you thought you had declared it as and find the right name and when you do this the error goes away.

    Otherwise you can set on variable, try using the mistyped variable name - which would not have the correct value in and you code could break for unexpected reasons further down because of a mistyped variable name.

    So I would very strongly recommend you keep it on.


  • Ather.

    but i dun get where i can find the objectype

    jux like this code

    "intRndNo = _" how do i know which objecttype is that


  • crash33

    OK I'll lay this out clearly.

    You are using variables such as blnFullSetComplete before you have declared them.

    You need to use a statement like dim blnFullSetComplete as Boolean beforehand to specifically declare the variable and type prior to using it.

    This is probably because you have used option explicit on.

    It doesnt matter the variable name, type or construct you are using it in - the same thing applies - you need to declare the variables before you use them.


  • Joos

    hey man, i finished that part already, can u answer my question in my other thread
  • Zatoichi

    i got one more question......

    "For intForLoopCtr As Integer = 1 To CInt(txtNoPics.Text)" this is working, but then after i type ur code, then i enter the next code, and the code is " Do until blnFullSetComplete = True "

    But then it said blnFullSetComplete is not delclared, so u got any more method again >.>


  • Puca

    That line makes no sense (unless the underscore is a line continuation character). It looks like the declaration indicates it should be an integer: but where is it being used You ould have to tell us.

    dim intRndNo as integer

    however, I'd probably declare it as something a bit more descriptive such as:

    dim NextRandomNumber as integer

    These are declarations.

    Read the answers you have recieved: you have to declare all the objects you are going to use. An object can be an integer, a boolean, a class an array, etc. VB needs to know what it is so it can deal with it: you have to explicitly tell the compiler what it is dealing with.



  • KenRW

    the next line is this " FormatNumber (Int((txtNoRange.text * Rnd()) +1))"
  • Nimrod_

    im going to try
  • nbaker

    Spotty raises a good point... because you've got 'option explicit' on (which is the default), you have to declare any variables before you can use them... if you really want to go without this saftey net you can insert the following line at the top of any file you want to be able to use a variable without having to declare it ahead of time:

    Option Explicit Off



  • Error While Coding!!