Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
Photo

vb 2005 help


  • Please log in to reply

#1
jeffsimmo85

jeffsimmo85

    Member

  • Member
  • PipPip
  • 16 posts
im working on a project to collect information on dvds from the people who use it, its all pretty simple and ive got the majority of the program working. But im having a problem with how the information is viewed once its been saved by the user into an array.
i have a form to enter where the user enters in 4 seperate pieces of information about the dvd into 4 seperate text boxes, then a save button which saves it all to an array. this works fine but on the main form where the information is displayed i cant get the previous and next buttons to go to the next or previous information in the array without getting some form of error after a few clicks. when the next button is clicked it shows the first set of information in the array fine and can keep going round the array, but when i click the previous button and then use the next button again i get an error.

i was wondering if anyone could help me with this as ive tried near enough everything and i know it will probably be a small error or missed out bit of code.

the code is:

NEXT BUTTON sub =

If counter > numdvds - 1 Then
counter = 0
End If

With Details(counter)
TxtTitle.Text = .Title
TxtDirector.Text = .Director
TxtYear.Text = .Year
TxtRating.Text = .Rating
PBoximage.ImageLocation = .dvdimage
End With
counter = counter + 1


PREVIOUS BUTTON sub =

If counter < 0 Then
counter = numdvds - 1
End If

With Details(counter)
TxtTitle.Text = .Title
TxtDirector.Text = .Director
TxtYear.Text = .Year
TxtRating.Text = .Rating
PBoximage.ImageLocation = .dvdimage
End With
counter = counter - 1



just wondering if theres any other way i could do it to make it work correctly? would really appreciate any help. thanks
  • 0

Advertisements


#2
stettybet0

stettybet0

    Trusted Tech

  • Technician
  • 2,579 posts
Giving us all relevant code would help a lot. For example, what values do numdvds and counter start with?

Edited by stettybet0, 17 April 2007 - 01:28 PM.

  • 0

#3
jeffsimmo85

jeffsimmo85

    Member

  • Topic Starter
  • Member
  • PipPip
  • 16 posts

Giving us all relevant code would help a lot. For example, what values do numdvds and counter start with?



seing as how you've put this, i'm also having another small problem which i cant work out because i have never been taught it. as i said the user enters the data into the program by 4 text boxes and an add button, when they click the add button the data goes into the 4 parts of the array(.title, .director, .year, .rating) s but i have declaired the array in the module like this :

Structure DvdDetails
Public Title As String
Public Director As String
Public Year As String
Public Rating As Integer
Public dvdimage As String
End Structure

Public Details(10) As DvdDetails
Public counter As Integer
Public numdvds As Integer


so at the moment there can only be 10 dvds added by the user until the array is full.... i could make this to 100 or something like that but i thought theres a way you can do it making it grow when a new item is put into the array?

the code for the add button is

With Details(numdvds)
.Title = Txtaddtitle.Text
.Director = TxtaddDirector.Text
.Year = TxtaddYear.Text
.Rating = Val(TxtaddRating.Text)
.dvdimage = PBoximage.ImageLocation
End With
numdvds = numdvds + 1

so numdvds grows wit the size of the array and i thought i could put that instead of the size 10 part when declaring the array but that didnt work.

so any help / suggestions would be really helpful, i know it maybe something simple or obvious but ive not been using vb for long and theres still some things that i just cant work out.
thanks
  • 0

#4
stettybet0

stettybet0

    Trusted Tech

  • Technician
  • 2,579 posts
to make a resizeable array, do this:

Public Details() As DvdDetails

then in the add button code:

numdvds = numdvds + 1
ReDim Details(numdvds)
With Details(numdvds)
	.Title = Txtaddtitle.Text
	.Director = TxtaddDirector.Text
	.Year = TxtaddYear.Text
	.Rating = Val(TxtaddRating.Text)
	.dvdimage = PBoximage.ImageLocation
End With

let me know if this helps any.

Edited by stettybet0, 17 April 2007 - 05:11 PM.

  • 0

#5
jeffsimmo85

jeffsimmo85

    Member

  • Topic Starter
  • Member
  • PipPip
  • 16 posts

to make a resizeable array, do this:

Public Details() As DvdDetails

then in the add button code:

numdvds = numdvds + 1
ReDim Details(numdvds)
With Details(numdvds)
	.Title = Txtaddtitle.Text
	.Director = TxtaddDirector.Text
	.Year = TxtaddYear.Text
	.Rating = Val(TxtaddRating.Text)
	.dvdimage = PBoximage.ImageLocation
End With

let me know if this helps any.


i got the same error saying it had gone out of the boundaries of the array :[ ive been trying so much different stuff to sort it and nothing works
  • 0

#6
jeffsimmo85

jeffsimmo85

    Member

  • Topic Starter
  • Member
  • PipPip
  • 16 posts

to make a resizeable array, do this:

Public Details() As DvdDetails

then in the add button code:

numdvds = numdvds + 1
ReDim Details(numdvds)
With Details(numdvds)
	.Title = Txtaddtitle.Text
	.Director = TxtaddDirector.Text
	.Year = TxtaddYear.Text
	.Rating = Val(TxtaddRating.Text)
	.dvdimage = PBoximage.ImageLocation
End With

let me know if this helps any.


i got the same error saying it had gone out of the boundaries of the array :[ ive been trying so much different stuff to sort it and nothing works


after saying that, i realised it may of actually worked, its just the fact that i cant scroll through them with the next and previous buttons because the code for them still isnt correct as i said before :\
  • 0

#7
stettybet0

stettybet0

    Trusted Tech

  • Technician
  • 2,579 posts
i'm currently working on a code to fix the buttons... it should be done shortly just hang tight.
  • 0

#8
jeffsimmo85

jeffsimmo85

    Member

  • Topic Starter
  • Member
  • PipPip
  • 16 posts

i'm currently working on a code to fix the buttons... it should be done shortly just hang tight.


cheers, im really greatful for your help
  • 0

#9
stettybet0

stettybet0

    Trusted Tech

  • Technician
  • 2,579 posts
okay... just put these codes in the appropriate locations:

Define variables:
Structure DvdDetails
		Public Title As String
		Public Director As String
		Public Year As String
		Public Rating As Integer
		Public dvdimage As String
	End Structure
	Public Details() As DvdDetails
	Public counter As Integer
	Public numdvds As Integer

Add button:
numdvds = numdvds + 1
		ReDim Preserve Details(numdvds)
		With Details(numdvds)
			.Title = Txtaddtitle.Text
			.Director = TxtaddDirector.Text
			.Year = TxtaddYear.Text
			.Rating = Val(TxtaddRating.Text)
			.dvdimage = PBoximage.ImageLocation
		End With
		Txtaddtitle.Text = ""
		TxtaddDirector.Text = ""
		TxtaddYear.Text = ""
		TxtaddRating.Text = ""

Next button:
counter = counter + 1
		If counter > numdvds Then
			counter = 1
		End If
		With Details(counter)
			TxtTitle.Text = .Title
			TxtDirector.Text = .Director
			TxtYear.Text = .Year
			TxtRating.Text = .Rating
			PBoximage.ImageLocation = .dvdimage
		End With

Previous button:
counter = counter - 1
		If counter <= 0 Then
			counter = numdvds
		End If
		With Details(counter)
			TxtTitle.Text = .Title
			TxtDirector.Text = .Director
			TxtYear.Text = .Year
			TxtRating.Text = .Rating
			PBoximage.ImageLocation = .dvdimage
		End With

Let me know how that works out.
  • 0

#10
jeffsimmo85

jeffsimmo85

    Member

  • Topic Starter
  • Member
  • PipPip
  • 16 posts
That has worked perfectly! :whistling:
thankyou so much.
one last question as all the other parts of the program are working, my only other problem which i have just found. is that i have also got a save and load function and all they do is write all the code from each part of the array into a text file and then read them back in when its loaded. but now the arrays working fine i have tested it and if you add some dvds to the collection then click load to load in others that were already saved, it goes over the the dvds that have just been added into the array.
the code for the save and load is

save =

Dim outputfile As StreamWriter
outputfile = File.CreateText("DVDs.txt")

Dim i As Integer

For i = 0 To numdvds - 1
With Details(i)
outputfile.WriteLine(.Title)
outputfile.WriteLine(.Director)
outputfile.WriteLine(.Year)
outputfile.WriteLine(.Rating)
outputfile.WriteLine(.dvdimage)
End With
Next i

outputfile.Close()



load =

Dim i As Integer

Dim inputfile As StreamReader
inputfile = File.OpenText("DVDs.txt")

While Not inputfile.EndOfStream

With Details(i)
.Title = inputfile.ReadLine()
.Director = inputfile.ReadLine()
.Year = inputfile.ReadLine()
.Rating = inputfile.ReadLine()
.dvdimage = inputfile.ReadLine()
End With
i = i + 1

End While

inputfile.Close()

numdvds = i


would it be something to do with the 'numvids = i' part?
im not to sure, its no problem if you dont have the time, i really appreciate the help on the other part.
thanks
  • 0

Advertisements


#11
stettybet0

stettybet0

    Trusted Tech

  • Technician
  • 2,579 posts
Let me make sure I understand the problem:

so say if you put dvds a, b, and c into the array, then save, then close the program. then you open the program and put dvds d, e, and f into the array, and then load. Then the only dvds that are there are a, b, and c. (d, e, and f have been overwritten)
  • 0

#12
jeffsimmo85

jeffsimmo85

    Member

  • Topic Starter
  • Member
  • PipPip
  • 16 posts

Let me make sure I understand the problem:

so say if you put dvds a, b, and c into the array, then save, then close the program. then you open the program and put dvds d, e, and f into the array, and then load. Then the only dvds that are there are a, b, and c. (d, e, and f have been overwritten)


thats exactly it yes, know how it could be fixed?
  • 0

#13
stettybet0

stettybet0

    Trusted Tech

  • Technician
  • 2,579 posts
save button:
Dim outputfile As IO.StreamWriter
		outputfile = IO.File.CreateText("DVDs.txt")
		Dim i As Integer
		For i = 1 To numdvds
			With Details(i)
				outputfile.WriteLine(.Title)
				outputfile.WriteLine(.Director)
				outputfile.WriteLine(.Year)
				outputfile.WriteLine(.Rating)
				outputfile.WriteLine(.dvdimage)
			End With
		Next i
		outputfile.Close()

load button:
Dim i As Integer
		i = numdvds
		Dim inputfile As IO.StreamReader
		inputfile = IO.File.OpenText("DVDs.txt")
		While Not inputfile.EndOfStream
			i = i + 1
			ReDim Preserve Details(i)
			With Details(i)
				.Title = inputfile.ReadLine()
				.Director = inputfile.ReadLine()
				.Year = inputfile.ReadLine()
				.Rating = inputfile.ReadLine()
				.dvdimage = inputfile.ReadLine()
			End With
			numdvds = i
		End While
		inputfile.Close()

  • 0

#14
jeffsimmo85

jeffsimmo85

    Member

  • Topic Starter
  • Member
  • PipPip
  • 16 posts

save button:

Dim outputfile As IO.StreamWriter
		outputfile = IO.File.CreateText("DVDs.txt")
		Dim i As Integer
		For i = 1 To numdvds
			With Details(i)
				outputfile.WriteLine(.Title)
				outputfile.WriteLine(.Director)
				outputfile.WriteLine(.Year)
				outputfile.WriteLine(.Rating)
				outputfile.WriteLine(.dvdimage)
			End With
		Next i
		outputfile.Close()

load button:
Dim i As Integer
		i = numdvds
		Dim inputfile As IO.StreamReader
		inputfile = IO.File.OpenText("DVDs.txt")
		While Not inputfile.EndOfStream
			i = i + 1
			ReDim Preserve Details(i)
			With Details(i)
				.Title = inputfile.ReadLine()
				.Director = inputfile.ReadLine()
				.Year = inputfile.ReadLine()
				.Rating = inputfile.ReadLine()
				.dvdimage = inputfile.ReadLine()
			End With
			numdvds = i
		End While
		inputfile.Close()



thank you so much, that works perfectly :whistling:
  • 0

#15
stettybet0

stettybet0

    Trusted Tech

  • Technician
  • 2,579 posts
no problem, just let me know if you have any more questions.
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP