"open file" replacement for vb.net

  • (2 Pages)
  • +
  • 1
  • 2

16 Replies - 2742 Views - Last Post: 14 December 2011 - 01:23 PM Rate Topic: -----

#1 mapmd1234  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 147
  • Joined: 04-December 09

"open file" replacement for vb.net

Posted 14 December 2011 - 10:07 AM

so upon going through the code for what I've got transferred into the vb.net version, and upon debugging the current code, vb.net tells me that the "open" command is not correct and or not supported in the vb.net platform, it gives an error of "Error 1 'Open' is not declared. File I/O functionality is available in the 'Microsoft.VisualBasic' namespace."

what the heck does this mean, and how the heck should I go about fixing this?? because quite frankly, I do not understand what this error is telling me...If I had to venture a guess, I want to say that it is telling me that vb.net express does not allow for such a function...but I'm definitely hoping that that is a wrong thought...because otherwise I'm quite frankly screwed...

upon reading more into the debugging, theres a few more bugs that I'm not sure what to do about...the code is as follows:
Open (file) For Input As #intf
        Do While Not EOF(intf)
        Input #intf, txtInput
            praz = praz + txtInput
        Loop
Close #intf



and the errors are as follows where the first line is line 37:
end of statement expected 37
expression expected 39
method argument must be enclosed in parentheses 39
close is not declared. file i/o functionality is available in the 'microsoft.visualbasic' namespace 42
expression expected 42

This post has been edited by mapmd1234: 14 December 2011 - 10:17 AM


Is This A Good Question/Topic? 0
  • +

Replies To: "open file" replacement for vb.net

#2 trevster344  Icon User is offline

  • The Peasant
  • member icon

Reputation: 224
  • View blog
  • Posts: 1,511
  • Joined: 16-March 11

Re: "open file" replacement for vb.net

Posted 14 December 2011 - 10:15 AM

You can import microsoft.visualbasic namespace and then you'll be able to use a whole slew of commands from vb6 days. Otherwise just use the system.io name space. It has plenty of other namespaces that will handle lots if not most file operations.
Was This Post Helpful? 1
  • +
  • -

#3 mapmd1234  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 147
  • Joined: 04-December 09

Re: "open file" replacement for vb.net

Posted 14 December 2011 - 10:18 AM

View Posttrevster344, on 14 December 2011 - 05:15 PM, said:

You can import microsoft.visualbasic namespace and then you'll be able to use a whole slew of commands from vb6 days. Otherwise just use the system.io name space. It has plenty of other namespaces that will handle lots if not most file operations.

considereing that all of the code is from the vb6 version, Ill ask how you go about importing the microsoft.visualbasic namespace
Was This Post Helpful? 0
  • +
  • -

#4 trevster344  Icon User is offline

  • The Peasant
  • member icon

Reputation: 224
  • View blog
  • Posts: 1,511
  • Joined: 16-March 11

Re: "open file" replacement for vb.net

Posted 14 December 2011 - 10:22 AM

Outside your class type Imports Microsoft.Visualbasic although I think you might need to import Microsoft.VisualBasic.Compatibility since the othername space is generally referenced by default. You can also open your project properties, go to references, and add a new reference to a namespace.
Was This Post Helpful? 0
  • +
  • -

#5 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9570
  • View blog
  • Posts: 36,240
  • Joined: 12-June 08

Re: "open file" replacement for vb.net

Posted 14 December 2011 - 10:22 AM

What's the line of code it's happening on?

Also I would advise against leaning on the crutch and using the old vb6 name space... you're in .NET - cut the ties!
Was This Post Helpful? 0
  • +
  • -

#6 trevster344  Icon User is offline

  • The Peasant
  • member icon

Reputation: 224
  • View blog
  • Posts: 1,511
  • Joined: 16-March 11

Re: "open file" replacement for vb.net

Posted 14 December 2011 - 10:25 AM

View Postmodi123_1, on 14 December 2011 - 11:22 AM, said:

What's the line of code it's happening on?

Also I would advise against leaning on the crutch and using the old vb6 name space... you're in .NET - cut the ties!


Agreed. You'll find it's a wonderful change.
Was This Post Helpful? 0
  • +
  • -

#7 mapmd1234  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 147
  • Joined: 04-December 09

Re: "open file" replacement for vb.net

Posted 14 December 2011 - 10:27 AM

the line(s) of code that its happening on were stated in my original post, and I'd love to try to use nothing but the .net programming language with this program, because once I get the hang of it, I know that it will be better...
Was This Post Helpful? 0
  • +
  • -

#8 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9570
  • View blog
  • Posts: 36,240
  • Joined: 12-June 08

Re: "open file" replacement for vb.net

Posted 14 December 2011 - 10:43 AM

Yeah, use the "stream reader" namespace!
Was This Post Helpful? 0
  • +
  • -

#9 mapmd1234  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 147
  • Joined: 04-December 09

Re: "open file" replacement for vb.net

Posted 14 December 2011 - 10:45 AM

ill try that now, thank you...
Was This Post Helpful? 0
  • +
  • -

#10 mapmd1234  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 147
  • Joined: 04-December 09

Re: "open file" replacement for vb.net

Posted 14 December 2011 - 10:53 AM

ok, I looked through the references part of the program, couldn't find it there, then tried to use it in code, but how would I go about using streamreader/streamwriter to open a file as the next available file possible, write to it, and or then in another instance read from it??

wow...man do I feel dumb now...I just realized that I don't have to be using this bit of code that I am working on right now...it is part of the encryption/decryption part of the game...so never mind, I will come back to this topic at a later date I guess...

This post has been edited by mapmd1234: 14 December 2011 - 10:57 AM

Was This Post Helpful? 0
  • +
  • -

#11 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9570
  • View blog
  • Posts: 36,240
  • Joined: 12-June 08

Re: "open file" replacement for vb.net

Posted 14 December 2011 - 10:56 AM

http://msdn.microsof...reamreader.aspx

Did you look at the example at the bottom of the msdn page?
Was This Post Helpful? 0
  • +
  • -

#12 mapmd1234  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 147
  • Joined: 04-December 09

Re: "open file" replacement for vb.net

Posted 14 December 2011 - 12:03 PM

no I did not read that, although upon trying to read that, it slightly, ever so slightly, makes sense to me, but I still cant figure out how the heck I should modify it to my needs, and upon trying for 2 hours now to use the microsoft.visualbasic options, it just keeps confusing me more and more the more I get it to accept my code properly... so I'm just going to post the large chunk of problem code, and hope that someone is willing to humor me enough to help me fix the code, because for the life of me, I cannot figure it out myself... so seeing as it is a rather huge chunk of code, I'm doubtful anyone will be willing to humor me enough to either fix it, or to help me to understand enough of whats going on here to help me figure out for myself what I need to do...but either way, I have to be going here soon...so I'll probably have to get back on here later on tonight to get it done... but thankfully i decided I'd work ahead to convert the code prior to starting my class...and boy am I glad I did.

Public Module fileops
 Option Explicit
    Dim temp As String
    Dim name As String
    Dim pass As String
    Dim letter As String
    Dim x, c As Integer
    Dim intf As Integer
Dim stat(1 To 19) As Integer
Dim Sstat(1 To 19) As String
    Public Sub save(ByVal path As String)
        path = App.path & "/" & Stats.CI.charactername & " the " & Stats.CI.speciesname & ".txt"
        intf = FreeFile
Open path For Output As #intf
    Write #intf, Stats.CI.charactername
    Write #intf, Stats.CI.password
        'Write #intf, Stats.CI.species
    Write #intf, Stats.CI.agility
    Write #intf, Stats.CI.dexterity
    Write #intf, Stats.CI.endurance
    Write #intf, Stats.CI.health
    Write #intf, Stats.CI.intelect
    Write #intf, Stats.CI.parry
    Write #intf, Stats.CI.speed
    Write #intf, Stats.CI.strength
    Write #intf, Stats.CI.totalexp
    Write #intf, Stats.CI.health
    Write #intf, Stats.CI.exphave
    Write #intf, Stats.CI.expleftover
    Write #intf, Stats.CI.expneed
    Write #intf, Stats.CI.Level
    Write #intf, Stats.CI.maxdamage
    Write #intf, Stats.CI.MaxHealth
    Write #intf, Stats.CI.mindamage
    Write #intf, Stats.CI.skillpoints
    Write #intf, Stats.CI.turnspeed
Close #intf
        'shroud.encrypt (path)
    End Sub
    Public Sub load(ByVal path As String)
        path = (App.path & "/" & Stats.CI.charactername & " the " & Stats.CI.speciesname & ".txt")
        intf = FreeFile
        x = 0
        'shroud.decrypt (path)
Open path For Input As #intf
    Input #intf, name
    Input #intf, pass
        Do Until EOF(intf)
        Input #intf, temp
            If temp = name Or temp = pass Then
                temp = ""
            Else
                x = x + 1
                For c = 1 To Len(temp)
                    letter = Mid(temp, c, 1)
                    If letter = "1" Or letter = "2" Or letter = "3" Or letter = "4" Or letter = "5" Or letter = "6" Or letter = "7" Or letter = "8" Or letter = "9" Then
                        Sstat(x) = Sstat(x) + letter
                    End If
                Next c
            End If
        Loop
        For x = 1 To 19
            stat(x) = Val(Sstat(x))
        Next x
        Stats.CI.charactername = name
        Stats.CI.password = pass
        Stats.CI.agility = stat(1)
        Stats.CI.dexterity = stat(2)
        Stats.CI.endurance = stat(3)
        Stats.CI.health = stat(4)
        Stats.CI.intelect = stat(5)
        Stats.CI.parry = stat(6)
        Stats.CI.speed = stat(7)
        Stats.CI.strength = stat(8)
        Stats.CI.totalexp = stat(9)
        Stats.CI.health = stat(10)
        Stats.CI.exphave = stat(11)
        Stats.CI.expleftover = stat(12)
        Stats.CI.expneed = stat(13)
        Stats.CI.Level = stat(14)
        Stats.CI.maxdamage = stat(15)
        Stats.CI.MaxHealth = stat(16)
        Stats.CI.mindamage = stat(17)
        Stats.CI.skillpoints = stat(18)
        Stats.CI.turnspeed = stat(19)
Close #intf
        'shroud.encrypt (path)
    End Sub
    Public Sub log(ByVal path As String, ByVal namec As String)
        intf = FreeFile
        If Dir$(path) = "" Then
    Open App.path For Output As #intf
        Write #intf, namec
    Close #intf
        Else
    Open path For Input As #1
    Open Left(App.path, 2) + "\temp.txt" For Output As #2
            Do Until EOF(1)
            Input #1, name
            Write #2, name
            Loop
            Write #2, namec
    Close #2
    Close #1
            Kill(path)
    Open path For Output As #1
    Open Left(App.path, 2) + "\temp.txt" For Input As #2
            Do Until EOF(2)
            Input #2, name
            Write #1, name
            Loop
    Close #2
    Close #1
            Kill(Left(App.path, 2) + "\temp.txt")
        End If
    End Sub
    Public Sub load_log(ByVal path As String, ByVal box As ComboBox)
        intf = FreeFile
        box.clear()
Open path For Input As #intf
        Do Until EOF(intf)
        Input #intf, temp
            box.AddItem(temp)
        Loop
Close #intf
    End Sub
    Public Sub clear()
        CI.charactername = ""
        CI.password = ""
        CI.expneed = 0
        CI.skillpoints = 0
        CI.exphave = 0
        CI.totalexp = 0
        CI.expleftover = 0
        CI.strength = 0
        CI.endurance = 0
        CI.intelect = 0
        CI.dexterity = 0
        CI.agility = 0
        CI.mindamage = 0
        CI.maxdamage = 0
        CI.MaxHealth = 0
        CI.speed = 0
        CI.health = 0
        CI.Level = 0
        CI.parry = 0
        CI.turnspeed = 0
        Game_window.Hide()
        play_b4.Show()
    End Sub

End Module



and I'm having multiple problems with this code...for starters there is the problem of my partners log system which might actually now be useless due to my login system, so forget about that one...I just realized that part...but the file input/output is the problem I'm facing that I cannot figure out what to change...

please and thank you for anyone whom has enough sanity and patience with me to help, but quite honestly, I couldn't blame you if you choose not to help...really couldn't...
Was This Post Helpful? 0
  • +
  • -

#13 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9570
  • View blog
  • Posts: 36,240
  • Joined: 12-June 08

Re: "open file" replacement for vb.net

Posted 14 December 2011 - 12:17 PM

Wait.. so you wrote this code in vb6, but are need "help me to understand enough of whats going on here to help me figure out for myself "?
Was This Post Helpful? 0
  • +
  • -

#14 mapmd1234  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 147
  • Joined: 04-December 09

Re: "open file" replacement for vb.net

Posted 14 December 2011 - 12:22 PM

more or less...yes it was written in vb6, but that code from vb6 I understand completely, what I need help understanding is what I need to change it to to get it to work the same way in vb.net so that I have a working save/load function again with which to then get back to working on continuing the rpg in the vb.net platform...so no, I don't need help to understand that part, what I need help to understand is all of the resources giving examples of how to read/write in vb.net, I get how that code works, but I do not understand how or what I need to do with say streamreader for example, to get it to work like or similarly as the vb6 code I have in order to get it to do the same end result...
Was This Post Helpful? 0
  • +
  • -

#15 trevster344  Icon User is offline

  • The Peasant
  • member icon

Reputation: 224
  • View blog
  • Posts: 1,511
  • Joined: 16-March 11

Re: "open file" replacement for vb.net

Posted 14 December 2011 - 01:05 PM

Your best bet is not trying to convert your programs over to VB.Net but trying to write new programs as if learning a completely new language. Start there, and later one when you get the hang of things, come back and try to convert it. The .Net framework is a giant collection of tools inside various namespaces. You have to reference these tools specifically, when you want to use them. For example if you want to use the streamreader you can either declare a new system.io.streamreader or you can import system.io.streamreader and then declare any variable as a streamreader object but you gotta use the new keyword to instance a new object. Some objects don't need to be instanced, and this is the part where I suggest you read up on objects, classes, inheritance etc. What I recall of vb6 is it doesn't blatantly expose objects. I hope what I've said was correct, if not anyone can correct me. Good luck sir.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2