Robert3234

I'm trying to get the location of an image from a picturebox. IE, if the image is being kept at: C:\Documents and Settings\Pictures\image.jpg i want to get that location from the picturebox, and then write it to a file. Here's a little sample of... the program itself:

Imports System.io
Public Class QuestionManager
Private Sub writeFile()
dim sw as streamwriter = new streamwriter("test.txt")
sw.writeline(PictureBox1.ImageLocation.tostring)
sw.close
end sub
end class

/\/\/\ end code

Ok, so when i run that sub (and yes, it is indeed being called) the file simply isn't written! When i change the sub around to just write something bogus like "sw.writeline("E")", it the file writes perfectly.

This problem is driving me CRAZY! Does anyone have any ideas as to what's going on Thanks so much! Any input is greatly appreciated
-Robert



Re: Visual Basic Express Edition PictureBox1.ImageLocation Problems

JohnWein

What value is in PictureBox1.ImageLocation Insert Debug.Print(PictureBox1.ImageLocation) before sw.writeline and look at the immediate window or look at tooltip. You probably don't have anything in ImageLocation if you loaded the image at design time.



Re: Visual Basic Express Edition PictureBox1.ImageLocation Problems

Robert3234

it prints what it should be printing... It's not loaded in at design time regardless





Re: Visual Basic Express Edition PictureBox1.ImageLocation Problems

Tall Dude

You may be looking for the file in the wrong place.

Try testing with the code below:

Imports System.IO

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles Button1.Click

Dim sw As StreamWriter = New StreamWriter("test.txt")

sw.WriteLine(PictureBox1.ImageLocation.ToString)

sw.Close()

If File.Exists("test.txt") Then

MsgBox("File does exist! " & vbCrLf & File.ReadAllText("test.txt"))

End If

End Sub

End Class






Re: Visual Basic Express Edition PictureBox1.ImageLocation Problems

Robert3234

Sir, you are something of a visionary. Although your solution wasn't altogether correct, it led me to what was going on. I was allowing the user to change the picture in the picturebox using an openfile dialog. Once i had chosen a file, it effectively switched the program's active directory, so when I was writing, i was actually writing to the directory that contained the pictures instead of the bin! Thanks so much!
-A very satisfied Robert