11 Replies - 702 Views - Last Post: 09 April 2009 - 10:47 AM Rate Topic: -----

#1 shootingstars  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 07-April 09

i don't know how to correct

Post icon  Posted 08 April 2009 - 06:31 PM

 option explicit

dim fso,line,data,grade,avg,sum
dim inFile,i
sum = 0

Set fso = CreateObject("Scripting.FileSystemObject")
set inFile = fso.openTextFile("grade.dat",1)

line = infile.readline()
do while not infile.AtEndOfStream

data = spit(line)
for i = 1 to 4 
sum = sum + data(i)
next
avg = sum/4
grade = getGrade(avg)
write(data(0) & vaTab & avg & vbTab & grade & vbCrLf)
sum = 0
line = infile.readline()
Loop
infile.close()

function getGrade(n)
dim grade
if n >= 90 then
   grade = "A"
elseif n >= 80 then
   grade = "B"
elseif n >= 70 then
   grade = "C"
elseif n >= 60 then
   grade = "D"
else
   grade = "F"
end if
   getGrade = grade 
end function

sub write(s)
 wscript.stdout.write(s)
end sub




who can help me correct it

Is This A Good Question/Topic? 0
  • +

Replies To: i don't know how to correct

#2 June7  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 104
  • View blog
  • Posts: 904
  • Joined: 09-December 08

Re: i don't know how to correct

Posted 08 April 2009 - 06:35 PM

What is not working? If you debugged and it bombed, what line of code failed?

This post has been edited by June7: 08 April 2009 - 06:50 PM

Was This Post Helpful? 0
  • +
  • -

#3 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1633
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: i don't know how to correct

Posted 08 April 2009 - 06:44 PM

Are you receiving any errors? Does this code not work that way you intended it? When asking for help there are a couple items that are vital in order for someone to properly help you:

  • Post the code you're having problems with (DONE)
  • Post the exact error you're receiving, if you are receiving one
  • If no error explain what the code is doing versus what you want it to do
  • Post your question in the body of your post, not the description field

Was This Post Helpful? 0
  • +
  • -

#4 shootingstars  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 07-April 09

Re: i don't know how to correct

Posted 08 April 2009 - 07:13 PM

sorry

option explicit

dim fso,line,data,grade,avg,sum
dim inFile,i
sum = 0

Set fso = CreateObject("Scripting.FileSystemObject")
set inFile = fso.OpenTextFile("C:\grade.dat",1)

line = infile.readline()
do while not infile.AtEndOfStream
data = split(line)
for i = 1 to 4 
  sum = sum + data(i)   error right here(subscript out of range:'1')
next
avg = sum/4
grade = getGrade(avg)
write(data(0) & vaTab & avg & vbTab & grade & vbCrLf)
sum = 0
line = infile.readline()
Loop
infile.close()

function getGrade(n)
dim grade
if n >= 90 then
   grade = "A"
elseif n >= 80 then
   grade = "B"
elseif n >= 70 then
   grade = "C"
elseif n >= 60 then
   grade = "D"
else
   grade = "F"
end if
   getGrade = grade 
end function

sub write(s)
 wscript.stdout.write(s)
end sub




error after for
Was This Post Helpful? 0
  • +
  • -

#5 June7  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 104
  • View blog
  • Posts: 904
  • Joined: 09-December 08

Re: i don't know how to correct

Posted 08 April 2009 - 07:39 PM

This error occurs when referencing a variable as an array but code doesn't recognize it as an array or you use a row/column index value outside the boundaries of the declared array. Think you need to declare 'data' as an array and define its boundaries (1 or 2 dimensions, how many rows) in a Dim statement. Right now it's just a variant. Else use a Redim statement in code before the For line. Check MS help if you need more familiarity with how to use arrays. Here's a tutorial I found with a quick search: http://patorjk.com/p...ls/vbarrays.htm

This post has been edited by June7: 08 April 2009 - 07:54 PM

Was This Post Helpful? 0
  • +
  • -

#6 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 463
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Re: i don't know how to correct

Posted 09 April 2009 - 01:14 AM

rly dude i avoid using array any way you are programing on VB6.0 witch i like most is becose i use vbalGrid for my buffer or array way easy and no need to define the how big to be :P try using one and make it visible=false all the time the simple user will never know it is there
Was This Post Helpful? 0
  • +
  • -

#7 GreaseMonkey  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 33
  • Joined: 23-March 09

Re: i don't know how to correct

Posted 09 April 2009 - 02:43 AM

View PostNoBrain, on 9 Apr, 2009 - 12:14 AM, said:

rly dude i avoid using array any way you are programing on VB6.0 witch i like most is becose i use vbalGrid for my buffer or array way easy and no need to define the how big to be :P try using one and make it visible=false all the time the simple user will never know it is there


avoid using arrays seriously dude are you taking the p***. yu can dynamically create arrays for one
dim array1() as integer	'blank, empty array'
dim i as integer

for i = 1 to 5
	redim preserve array1(1 to i) as integer
	'increments an array as much as need, the preserve keyword keeps all previous values intact
next i



and in response to the code throwing up the errors use this technique with the data variable. just remember to increase the array size before you do anything to it, therefore not throwing any errors up.
Was This Post Helpful? 1
  • +
  • -

#8 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 463
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Re: i don't know how to correct

Posted 09 April 2009 - 04:02 AM

dude when i study for core C devoleper they tell me not to use dynamically arrays for reasons that you must all time think what will hapen if the size you try to resize will be smaller then the one you have now. But still i am not so good programar ty for info :P :) GreaseMonkey

This post has been edited by NoBrain: 09 April 2009 - 04:07 AM

Was This Post Helpful? 0
  • +
  • -

#9 GreaseMonkey  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 33
  • Joined: 23-March 09

Re: i don't know how to correct

Posted 09 April 2009 - 10:09 AM

View PostNoBrain, on 9 Apr, 2009 - 03:02 AM, said:

dude when i study for core C devoleper they tell me not to use dynamically arrays for reasons that you must all time think what will hapen if the size you try to resize will be smaller then the one you have now. But still i am not so good programar ty for info :P :) GreaseMonkey


lulz no worries fella, i kinda has that been shoved down my neck with C++ because of memory addressing etc but you may as well take advatntage of it in VB, it saved my arse many of times :P
Was This Post Helpful? 0
  • +
  • -

#10 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 463
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Re: i don't know how to correct

Posted 09 April 2009 - 10:21 AM

yes the thing i like in VB :) C is kind a too strict

This post has been edited by NoBrain: 09 April 2009 - 10:23 AM

Was This Post Helpful? 0
  • +
  • -

#11 June7  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 104
  • View blog
  • Posts: 904
  • Joined: 09-December 08

Re: i don't know how to correct

Posted 09 April 2009 - 10:42 AM

Flex Grid control is handy. According to one of my references on VB you may have to install MSFlxGrd.ocx into \Windows\System.
Was This Post Helpful? 0
  • +
  • -

#12 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 463
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Re: i don't know how to correct

Posted 09 April 2009 - 10:47 AM

yep

This post has been edited by NoBrain: 09 April 2009 - 10:49 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1