5 Replies - 334 Views - Last Post: 18 August 2012 - 05:54 PM Rate Topic: -----

#1 Flitchit  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 17-August 12

[Question] VB.NET Load last quit position?

Posted 18 August 2012 - 12:02 AM

I am wanting to load the last position my application was at before it was quit, and I came up with a solution: When quitting, save the pos (position) into a .txt file (X on first line, Y on second line) and have it load that in Form1_Load. It saves alright

         My.Computer.FileSystem.DeleteFile("C:\pos.txt")
        My.Computer.FileSystem.WriteAllText("C:\pos.txt", Me.Location.X & vbNewLine & Me.Location.Y, True)
        End 


But loading that pos I need to read line's 1 and 2 individually, so I have done this, which has not worked and I need help with:

Me.Location = New Point(Me.Location.X = IO.File.ReadAllLines("C:\pos.txt")(0).ToString, Me.Location.Y = IO.File.ReadAllLines("C:\pos.txt")(1).ToString)



I have tried without the .ToString.

Is This A Good Question/Topic? 0
  • +

Replies To: [Question] VB.NET Load last quit position?

#2 smohd  Icon User is offline

  • Critical Section
  • member icon



Reputation: 1745
  • View blog
  • Posts: 4,409
  • Joined: 14-March 10

Re: [Question] VB.NET Load last quit position?

Posted 18 August 2012 - 12:32 AM

First using settings here will be much easier. But if you want to use files, you can save the data and differentiate them with some delimiter like ",":
My.Computer.FileSystem.WriteAllText("C:\pos.txt", Me.Location.X & "," & Me.Location.Y, True)

Then when reading, you read the line and split it! That is just it, read once and then split it to get your values.
Was This Post Helpful? 0
  • +
  • -

#3 Flitchit  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 17-August 12

Re: [Question] VB.NET Load last quit position?

Posted 18 August 2012 - 01:04 AM

View Postsmohd, on 18 August 2012 - 12:32 AM, said:

First using settings here will be much easier. But if you want to use files, you can save the data and differentiate them with some delimiter like ",":
My.Computer.FileSystem.WriteAllText("C:\pos.txt", Me.Location.X & "," & Me.Location.Y, True)

Then when reading, you read the line and split it! That is just it, read once and then split it to get your values.


Im sorry but Im not sure how to 'Split it', could you elaborate/give rough code?
Was This Post Helpful? 0
  • +
  • -

#4 Ionut  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 385
  • View blog
  • Posts: 1,053
  • Joined: 17-July 10

Re: [Question] VB.NET Load last quit position?

Posted 18 August 2012 - 01:31 AM

He meant string.Split function
Was This Post Helpful? 1
  • +
  • -

#5 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 1948
  • View blog
  • Posts: 8,665
  • Joined: 29-May 08

Re: [Question] VB.NET Load last quit position?

Posted 18 August 2012 - 04:09 PM

I agree with smohd on their point, using setting will so much simpler.

Tutorial: Using Settings

This post has been edited by AdamSpeight2008: 18 August 2012 - 04:09 PM

Was This Post Helpful? 0
  • +
  • -

#6 Flitchit  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 17-August 12

Re: [Question] VB.NET Load last quit position?

Posted 18 August 2012 - 05:54 PM

View PostAdamSpeight2008, on 18 August 2012 - 04:09 PM, said:

I agree with smohd on their point, using setting will so much simpler.

Tutorial: Using Settings


Yes, yes it would be. However I would like to to it my way, so that I can learn how to read options from each line, eg
in .txt:


fullscreen=0
showintskbar=1
pos,x,y=17,55
size,x,y=50,100

'<-- Write anything, It wont be read

etc. And also I know all this can be done with settings, but this way it makes it so users can easily change settings without having a 'settings' form and stuff like that.
So anyone know how to do something like


Private Sub Form1_Load
    dim pos as string
    pos = IO.File.ReadAllText("C:\pos.txt")
    If pos.line2 = "showintskbar=1" then
        Me.ShowInTaskbar = False
    end if
end sub


Obviously it wont be like that, but along the same lines (see what i did there? :P)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1