Welcome to Dream.In.Code
Getting VB.NET Help is Easy!

Join 136,455 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,950 people online right now. Registration is fast and FREE... Join Now!




PSP Sync Program strange error

 
Reply to this topicStart new topic

PSP Sync Program strange error

NIXZ
26 Jul, 2008 - 08:01 AM
Post #1

D.I.C Head
**

Joined: 26 Jul, 2008
Posts: 87

Its a Program i created to Sync PSP with my PC (like psp manager)
you browse through titles (images) add/remove/sync options plus a
connectivity test but when i start the "Sync.exe" VB Studio 2008 says
that theres a problem with this code:

CODE

Dim Bypass
Dim Value As Short
Bypass = FreeFile()
FileOpen(Bypass, "CTRL\Config\Bypass.dat", OpenMode.Input)
Input(Bypass, Value)
FileClose(Bypass)


Spesific with this:

CODE

Input(Bypass, Value)


Error: "Late bound calls to file system methods in the Visual Basic runtime
are not permitted." What ???
I Just dont get it why does there has to be something wrong with file permissions
when you open it through a program that has created the file?


Whats wrong with the script???

Heres the Source code for "Sync.exe":
CODE


Public Class Form1

Private Sub Button_Left_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Left.Click
Dim Object_FSO, Bypass_File, Bypass
Dim Number As Short
Dim Value As Short
On Error GoTo runtime_error
Number = FreeFile()
FileOpen(Number, "UMD\Number.dat", OpenMode.Input)
Input(Number, Value)
FileClose(Number)
If Value = 1 Then
MsgBox("You havent Imported any Title Yet.", 0 + 64, "PSP Sync - Library")
GoTo endsub
End If
Object_FSO = CreateObject("scripting.FileSystemObject")
If Object_FSO.FileExists("CTRL\Config\Bypass.dat") Then
GoTo Bypass
Else
Number = FreeFile()
FileOpen(Number, "UMD\Number.dat", OpenMode.Input)
Input(Number, Value)
FileClose(Number)
Bypass_File = FreeFile()
FileOpen(Bypass_File, "CTRL\Config\Bypass.dat", OpenMode.Output)
WriteLine(Bypass_File, Value)
FileClose(Bypass_File)
Object_FSO = CreateObject("scripting.FileSystemObject")
Bypass_File = Object_FSO.CreateTextFile("CTRL\Config\Bypass.dat", True)
Bypass_File.WriteLine(Value)
End If
Bypass:
Bypass = FreeFile()
FileOpen(Bypass, "CTRL\Config\Bypass.dat", OpenMode.Input)
Input(Bypass, Value)
FileClose(Bypass)
Dim Picture_Directory, Number_Value, Image_Directory, Title_Picture_Text, Title_File
Dim Title_Picture As Image
Number_Value = Value - 1
define:
If Object_FSO.FolderExists("UMD\" & Number_Value & "\") Then
GoTo loadimage
ElseIf Number_Value = 0 Then
Number = FreeFile()
FileOpen(Number, "UMD\Number.dat", OpenMode.Input)
Input(Number, Number_Value)
FileClose(Number)
GoTo define
Else
Number_Value = Value - 1
GoTo define
End If
loadimage:
On Error GoTo loadimage_error
Picture_Directory = FreeFile()
FileOpen(Picture_Directory, "UMD\" & Number_Value & "\Picture.dat", OpenMode.Input)
Input(Picture_Directory, Title_Picture_Text)
FileClose(Picture_Directory)
Title_Picture = Title_Picture_Text
PictureBox1.Image = Title_Picture
PictureBox1.Refresh()
Image_Directory = FreeFile()
FileOpen(Image_Directory, "CTRL\Config\Title.dat", OpenMode.Output)
WriteLine(Image_Directory, "UMD\" & Number_Value & "\")
FileClose(Image_Directory)
Bypass_File = Object_FSO.GetFile("CTRL\Config\Bypass.dat")
Bypass_File.Delete()
Bypass_File = FreeFile()
FileOpen(Bypass_File, "CTRL\Config\Bypass.dat", OpenMode.Output)
WriteLine(Bypass_File, Number_Value)
FileClose(Bypass_File)
If Object_FSO.FileExists("CTRL\Config\Title.dat") Then
Title_File = Object_FSO.GetFile("CTRL\Config\Title.dat")
Title_File.Delete()
Title_File = FreeFile()
FileOpen(Title_File, "CTRL\Config\Title.dat", OpenMode.Input)
Input(Title_File, "UMD\" & Number_Value & "\")
FileClose(Title_File)
Else
Title_File = FreeFile()
FileOpen(Title_File, "CTRL\Config\Title.dat", OpenMode.Input)
Input(Title_File, "UMD\" & Number_Value & "\")
FileClose(Title_File)
End If
GoTo endsub
loadimage_error:
MsgBox(Title_Picture_Text & " is not an Picture (*.jpg/*.bmp).", 0 + 16, "Runtime Error")
GoTo endsub
runtime_error:
MsgBox("Unexpected Error Aquired.", 0 + 16, "Runtime Error")
endsub:
End Sub

Private Sub Button_Add_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Add.Click
Dim Add
On Error GoTo runtime_error
Add = CreateObject("Wscript.Shell")
Add.Run("CTRL\Add.exe")
GoTo endsub
runtime_error:
MsgBox("Unexpected Error Aquired.", 0 + 16, "Runtime Error")
endsub:
End Sub

Private Sub Button_Sync_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Sync.Click
Dim Object_FSO, Title, CC, PSP_Drive_File, Image_Directory, Title_Directory, Number
Dim Value As Short
Dim Title_Directory_File As Short
Dim PSP_Drive As Short
On Error GoTo runtime_error
Number = FreeFile()
FileOpen(Number, "UMD\Number.dat", OpenMode.Input)
Input(Number, Value)
FileClose(Number)
If Value = 1 Then
MsgBox("You havent Imported any Title Yet.", 0 + 64, "PSP Sync - Library")
GoTo endsub
End If
Object_FSO = CreateObject("scripting.FileSystemObject")
If Object_FSO.FileExists("CTRL\Config\Title.dat") Then
Image_Directory = FreeFile()
FileOpen(Image_Directory, "CTRL\Config\Title.dat", OpenMode.Input)
Input(Image_Directory, Title_Directory)
FileClose(Image_Directory)
FileOpen(Image_Directory, Title_Directory & "Image.dat", OpenMode.Input)
Input(Image_Directory, Title_Directory_File)
FileClose(Image_Directory)
CC = CreateObject("Wscript.Shell")
CC.Run("CTRL\CC.bat")
wait:
If Object_FSO.FileExists("CTRL\Config\PSP_Drive.dat") Then
PSP_Drive_File = FreeFile()
FileOpen(PSP_Drive_File, "CTRL\Config\PSP_Drive.dat", OpenMode.Input)
Input(PSP_Drive_File, PSP_Drive)
FileClose(PSP_Drive_File)
Title = Object_FSO.GetFile(Title_Directory_File)
Title.Copy(PSP_Drive & "ISO\")
MsgBox("Sync Completed Successfully.", 0 + 64, "PSP Sync - Library")
GoTo endsub
Else
GoTo wait
End If
Else
MsgBox("Title's Image (*.iso/*.cso) is not Specified or Deleted.", 0 + 16, "Error")
GoTo endsub
End If
runtime_error:
MsgBox("Unexpected Error Aquired.", 0 + 16, "Runtime Error")
endsub:
End Sub

Private Sub Button_Remove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Remove.Click
Dim Object_FSO, Title_Remove, Title_Remove_Directory, Title_File_Remove_Directory, Number
Dim Value As Short
On Error GoTo runtime_error
Number = FreeFile()
FileOpen(Number, "UMD\Number.dat", OpenMode.Input)
Input(Number, Value)
FileClose(Number)
If Value = 1 Then
MsgBox("You havent Imported any Title Yet.", 0 + 64, "PSP Sync - Library")
GoTo endsub
End If
Object_FSO = CreateObject("scripting.FileSystemObject")
If Object_FSO.FileExists("CTRL\Config\Title.dat") Then
Title_Remove = FreeFile()
FileOpen(Title_Remove, "CTRL\Config\Title.dat", OpenMode.Input)
Input(Title_Remove, Title_Remove_Directory)
FileClose(Title_Remove)
FileOpen(Title_Remove, Title_Remove_Directory & "Image.dat", OpenMode.Input)
Input(Title_Remove, Title_File_Remove_Directory)
FileClose(Title_Remove)
Title_Remove = Object_FSO.GetFile(Title_File_Remove_Directory)
Title_Remove.Delete()
MsgBox("Title Exported from Library Successfully.", 0 + 16, "PSP Sync - Library")
GoTo endsub
Else
MsgBox("Title's Image (*.iso/*.cso) is not Specified or Deleted.", 0 + 16, "Error")
GoTo endsub
End If
runtime_error:
MsgBox("Unexpected Error Aquired.", 0 + 16, "Runtime Error")
endsub:
End Sub

Private Sub Button_Right_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Right.Click
Dim Object_FSO, Bypass_File, Bypass
Dim Number As Short
Dim Value As Short
On Error GoTo runtime_error
Number = FreeFile()
FileOpen(Number, "UMD\Number.dat", OpenMode.Input)
Input(Number, Value)
FileClose(Number)
If Value = 1 Then
MsgBox("You havent Imported any Title Yet.", 0 + 64, "PSP Sync - Library")
GoTo endsub
End If
Object_FSO = CreateObject("scripting.FileSystemObject")
If Object_FSO.FileExists("CTRL\Config\Bypass.dat") Then
GoTo Bypass
Else
Number = FreeFile()
FileOpen(Number, "UMD\Number.dat", OpenMode.Input)
Input(Number, Value)
FileClose(Number)
Bypass_File = FreeFile()
FileOpen(Bypass_File, "CTRL\Config\Bypass.dat", OpenMode.Output)
WriteLine(Bypass_File, Value)
FileClose(Bypass_File)
Object_FSO = CreateObject("scripting.FileSystemObject")
Bypass_File = Object_FSO.CreateTextFile("CTRL\Config\Bypass.dat", True)
Bypass_File.WriteLine(Value)
End If
Bypass:
Bypass = FreeFile()
FileOpen(Bypass, "CTRL\Config\Bypass.dat", OpenMode.Input)
Input(Bypass, Value)
FileClose(Bypass)
Dim Picture_Directory, Number_Value, Image_Directory, Title_Picture_Text, Title_File, Number_File
Dim Title_Picture As Image
Dim Number_Value_Define As Short
Number_Value = Value + 1
define:
Number_File = FreeFile()
FileOpen(Number_File, "UMD\Number.dat", OpenMode.Input)
Input(Number_File, Number_Value_Define)
FileClose(Number_File)
If Object_FSO.FolderExists("UMD\" & Number_Value & "\") Then
GoTo loadimage
ElseIf Number_Value = Number_Value_Define Then
Number_Value = 1
GoTo define
Else
Number_Value = Value + 1
GoTo define
End If
loadimage:
On Error GoTo loadimage_error
Picture_Directory = FreeFile()
FileOpen(Picture_Directory, "UMD\" & Number_Value & "\Picture.dat", OpenMode.Input)
Input(Picture_Directory, Title_Picture_Text)
FileClose(Picture_Directory)
Title_Picture = Title_Picture_Text
PictureBox1.Image = Title_Picture
PictureBox1.Refresh()
Image_Directory = FreeFile()
FileOpen(Image_Directory, "CTRL\Config\Title.dat", OpenMode.Output)
WriteLine(Image_Directory, "UMD\" & Number_Value & "\")
FileClose(Image_Directory)
Bypass_File = Object_FSO.GetFile("CTRL\Config\Bypass.dat")
Bypass_File.Delete()
Bypass_File = FreeFile()
FileOpen(Bypass_File, "CTRL\Config\Bypass.dat", OpenMode.Output)
WriteLine(Bypass_File, Number_Value)
FileClose(Bypass_File)
If Object_FSO.FileExists("CTRL\Config\Title.dat") Then
Title_File = Object_FSO.GetFile("CTRL\Config\Title.dat")
Title_File.Delete()
Title_File = FreeFile()
FileOpen(Title_File, "CTRL\Config\Title.dat", OpenMode.Input)
Input(Title_File, "UMD\" & Number_Value & "\")
FileClose(Title_File)
Else
Title_File = FreeFile()
FileOpen(Title_File, "CTRL\Config\Title.dat", OpenMode.Input)
Input(Title_File, "UMD\" & Number_Value & "\")
FileClose(Title_File)
End If
GoTo endsub
loadimage_error:
MsgBox(Title_Picture_Text & " is not an Picture (*.jpg/*.bmp).", 0 + 16, "Runtime Error")
GoTo endsub
runtime_error:
MsgBox("Unexpected Error Aquired.", 0 + 16, "Runtime Error")
endsub:
End Sub

End Class



User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: PSP Sync Program Strange Error
26 Jul, 2008 - 08:02 AM
Post #2

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 8,993



Thanked: 125 times
Dream Kudos: 8625
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
Moved to VB.NET smile.gif
User is offlineProfile CardPM
+Quote Post

jacobjordan
RE: PSP Sync Program Strange Error
26 Jul, 2008 - 09:27 AM
Post #3

class Me : Perfection
Group Icon

Joined: 11 Jun, 2008
Posts: 1,163



Thanked: 32 times
Dream Kudos: 1625
My Contributions
vb

FileOpen(Bypass, "CTRL\Config\Bypass.dat", OpenMode.Input)
Input(Bypass, Value)
FileClose(Bypass)

This is VB.NET, right? This is how i would of coded those lines
vb

FileOpen(1, "CTRL\Config\Bypass.dat", OpenMode.Input)
Input(1, Value)
FileClose(1)

You can see i've replaced the "Bypass" identifier in the fileopen method with an integer. In vb.net, only an integer can be used to identify an open file with the fileopen method. If you ran your app the way it was, it should of givin you an error on the fileopen line that said "Conversion from string "Bypass" to type 'Integer' is not valid.
User is offlineProfile CardPM
+Quote Post

danny_kay1710
RE: PSP Sync Program Strange Error
27 Jul, 2008 - 08:55 AM
Post #4

New D.I.C Head
*

Joined: 27 Apr, 2008
Posts: 19



Thanked: 1 times
My Contributions
You seem to be adopting a more VB6 approach to handling files. In .NET there are default in built functions to deal with files without having to reference Microsoft Scripting Runtime to use File System Objects.

Try replacing things such as fso.fileexists with system.io.file.exists.

System.IO.File <- is the native .NET Way of dealing with files
System.IO.Directory <- is the native way of dealing with folders
System.IO.path <- Has some interesting functions such as get file name without extension, get root directory path etc

If you want to read and write to a text file my advice would be to use System.IO.StreamReader and System.IO.StreamWriter

The other thing that your doing which takes a VB6 approach is error handling.

Your using On Error Goto statements which for all can be useful are not the best way to handle errors

You probably would be better off with Try..Catch..Finally Statements.

The way you would approach this would be to try something..catch any errors then clean up. See example below....

VB

Dim txtWriter as New System.io.StreamWriter("C:\test.txt")
Try
txtWriter.Writeline("Hello World")
' Do some more code
Catch ex as Exception
Messagebox.show(ex.message)
Finally
txtWriter.Close
End Try


That way no matter if an error occurs or not you can guarentee that the file gets closed properly.

Hope this helps although it may take a lot of doing.

Also the .NET replacement for msgbox is Messagebox.show(). You might find this gives you better functionality.

And yet another thing you can replace this late bounded call

vb
Add = CreateObject("Wscript.Shell")
Add.Run("CTRL\Add.exe")


with just

vb
shell("CTRL\Add.exe",1)


Edit: I honestly believe that the reason the program isn't working is because of the fact that your using latebounded calls to the scripting.filesystemobject object. I think if you were to change all the references to how I have them above then you would find it a lot easier to manage and debug. Especially considering intellisense will work when you use the above methods and they wont be for any of the fso objects your currently using.

This post has been edited by danny_kay1710: 27 Jul, 2008 - 09:12 AM
User is offlineProfile CardPM
+Quote Post

NIXZ
RE: PSP Sync Program Strange Error
27 Jul, 2008 - 10:36 AM
Post #5

D.I.C Head
**

Joined: 26 Jul, 2008
Posts: 87

Im lost its my first application i have choosen to create a new windows form application whats the difference of VB from VB.NET
i get that error "identifer expected" righting script "Dim 1 As Integer"...
Confused blink.gif
User is offlineProfile CardPM
+Quote Post

jacobjordan
RE: PSP Sync Program Strange Error
27 Jul, 2008 - 11:13 AM
Post #6

class Me : Perfection
Group Icon

Joined: 11 Jun, 2008
Posts: 1,163



Thanked: 32 times
Dream Kudos: 1625
My Contributions
QUOTE(NIXZ @ 27 Jul, 2008 - 01:36 PM) *

Im lost its my first application i have choosen to create a new windows form application whats the difference of VB from VB.NET
i get that error "identifer expected" righting script "Dim 1 As Integer"...
Confused blink.gif

"Dim 1 As Integer" is not valid. You can not name a variable with a number. If you are meaning to have an integer variable equal to 1, this is what you should do
vb

Dim One As Integer
One = 1

User is offlineProfile CardPM
+Quote Post

danny_kay1710
RE: PSP Sync Program Strange Error
27 Jul, 2008 - 11:52 AM
Post #7

New D.I.C Head
*

Joined: 27 Apr, 2008
Posts: 19



Thanked: 1 times
My Contributions
QUOTE(NIXZ @ 27 Jul, 2008 - 01:36 PM) *

Im lost its my first application i have choosen to create a new windows form application whats the difference of VB from VB.NET
i get that error "identifer expected" righting script "Dim 1 As Integer"...
Confused blink.gif


OK,

I am sorry to have confused you.

What I am trying to say is that your using unsupported approaches to many tasks.

This line of code enables all of your File System access

vb
Object_FSO = CreateObject("scripting.FileSystemObject")


This creates a COM object known as a filesystemobject. Creating an object in this way is known as late binding.
I think that the compiler is telling you that you cannot talk to the file system using a late binded object because there is no guarentee that the object you created exposes the functions you are calling.

So, in other words you have to replace all the code that references Object_FSO or not late bind it.
Personally replacing it is the best option albeit not the easiest.
To not late bind Add a reference to your project. Under the COM tab select Microsoft Scripting Runtime and add that.

Then replace the above line of code (all instances of it) with:

vb
        Dim Object_FSO As New Scripting.FileSystemObject


That may fix the problem. If that doesn't you will need to find alternatives for all of the object_FSO.something lines of code.

I hope this will clear things up for you.
Danny


User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 03:22PM

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month