|
Most likely it does not call itself, it is an event and the function has been added to the event twice, ergo it will be called twice.
Search your solution for the function name and see if it's being added to an event twice.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I have checked the project. It is a simple project and that is the only add button.
|
|
|
|
|
Have you searched for the function name ? Do so, and paste every line that contains the name of the function, I'm sure I'll find the problem from there.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
If the function name you are refering to is the objectDataSource.Insert(), that is an inbuilt func. there is no reason for it to be calling itself.
But at the end it does have a func call to refresh the gridview as the last line in the event, but when it comes back it goes through the whole event again.
localhostdatasource.Parameters..............
localhostdatasource.Insert()-------> inbuilt
gridload()--------> myfunc
sub gridload()
localhostdatasource.Select()
end sub
-- modified at 19:13 Tuesday 21st March, 2006
|
|
|
|
|
Dim rstrToAdd As Date = New Date(rosterCal.SelectedDate.Year, rosterCal.SelectedDate.Month, _
rosterCal.SelectedDate.Day, Integer.Parse(rstrHrList.SelectedItem.ToString), _
Integer.Parse(rstrMinList.SelectedItem.ToString), 0)
resultText.Text = rstrToAdd + " " + rosterCal.SelectedDate.DayOfWeek.ToString
localhostDataSource.InsertParameters.Clear()
localhostDataSource.InsertParameters.Add("dtRstr", TypeCode.DateTime, rstrToAdd)
localhostDataSource.InsertParameters.Add("day", TypeCode.String, rosterCal.SelectedDate.DayOfWeek.ToString)
localhostDataSource.Insert()
'gridLoad()
this is the add func
|
|
|
|
|
i'm not sure i did it right, but i think not cause it's not working. I had already save some line in the txt file, where now i trying to retrieve those infomation line by line to the other form. For the for loop section, anyone can tell me am i doing it right?
-----
Dim strmw As StreamReader
Dim myInputString As String
Dim filePath As String = Path.GetDirectoryName(Application.ExecutablePath) & "\save\testing.txt"
Dim x, num As Integer
Dim respond As MsgBoxResult
respond = MsgBox("Load file???", MsgBoxStyle.Question + MsgBoxStyle.YesNo)
If respond = MsgBoxResult.Yes Then
strmw = File.OpenText(filePath)
'loop the line for different person detail
num = strmw.ReadLine()
For x = 1 To Val(num)
' write detail in the record
x = strmw.ReadLine()
wpname(x).Text = strmw.ReadLine()
wPP(x).Text = strmw.ReadLine()
wcounter(x).Text = strmw.ReadLine()
Next
form2.PTurn.Text = strmw.ReadLine() 'get whos turn
strmw.Close()
MsgBox("Loading sucess", MsgBoxStyle.OKOnly)
Else: Exit Sub
End If
|
|
|
|
|
campbells wrote: but i think not cause it's not working
So what's not working about it? Have you traced the code in debug mode to see what is happening?
...Steve
1. quod erat demonstrandum
2. "Give a man a fish and you've fed him for a day. Teach him how to fish and you've fed him for life." I read that somewhere once
(Translation: I'll show you the way, but not write the code for you.)
|
|
|
|
|
num = strmw.ReadLine()
- i assume you have a number on the first line of your textfile
For x = 1 To Val(num)
- then you read another number and modified x, where x is your loop control counter
- the loop itself is pretty much destroyed with the next statement
<code> x = strmw.ReadLine()</code>
wpname(x).Text = strmw.ReadLine()<br />
wPP(x).Text = strmw.ReadLine()<br />
wcounter(x).Text = strmw.ReadLine() <br />
<br />
Next
you probably need to change your loop control. use <code>while .. do .. loop </code>instead
or you could post a sample of your data(textfile) so we could help you better and probably suggest
a working snippet.
Marvin N. Guerrero
- Taje Kage_bunshinNunJutsU
|
|
|
|
|
the game maybe have 1-4 player, so let said in this round have
3 players
player:1
NAme:A
Position:10
Movestep:2
player:2
NAme:B
Position:8
Movestep:2
player:3
NAme:C
Position:7
Movestep:2
-- so i was thinking to use the x value to loop 3 times since got 3 player
and read 4 line accordinly.... am not sure can it work but i only know a bit on using the readline.
|
|
|
|
|
This is a really inefficient way of doing this. You'd be better off writing it in a CSV format (commna delimited):
Name,Age,Sex,Something
"Amy",17,"F",123456
"Bobby",18,"M",123456
This will make it easier to parse and easier to recover from a lightly corrupted file.
Better yet, use XML!
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
?????? noo...
actually thats example only
wat i mean is i need to loading those information into some label.text, so that the form can perform some task according to the function.
|
|
|
|
|
And you didn't create this file? It's comming from an outside source that you don't control?
If you did, then my suggestion still stands. It in no way change what you want to do with this in relation to the forms controls.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
??nonono
i had already create the file here how i save it, so now i want to load the information back.
......................
respond = MsgBox("Save game ???", MsgBoxStyle.Question + MsgBoxStyle.YesNo)
If respond = MsgBoxResult.Yes Then
strmw = OpenStreamWriter(filePath)
strmw.Write(vbCrLf)
'loop all the player status
For x = 1 To Val(NumPlayer.Text)
' write detail in the record
strmw.WriteLine(String.Format("Player:" & (x), Now))
strmw.WriteLine(String.Format(" Name: " & wpname(x).Text, Now))
strmw.WriteLine(String.Format("position:" & wPP(x).Text, Now))
strmw.WriteLine(String.Format(" MoveStep:" & wcounter(x).Text, Now))
savegamesound()
Next
strmw.WriteLine(String.Format("whosturn: " & PTurn.Text, Now))
strmw.Close()
MsgBox("Game Saved", MsgBoxStyle.OKOnly)
Else : Exit Sub
End If
|
|
|
|
|
Nonononono!!! Since you control writing the file, you're doing it in such a way that makes it easy to write but also makes it very tedious to read it back in.
What's up with these Now 's?? Since your Format's don't have any parameters, calling Now all the time isn't doing anythis. And using String.Format doesn't benefit you either!
strmw.WriteLine(String.Format("Player:" & x, Now)) '?????????
If I was in your position, I'd be saving all my Player data into a collection of Player objects. Then you can just serialize the collection out to an XML file and read it back in just as easy.
Public Class Player
Private _PlayerName As String
Private _Position As Integer '? I don't know what data type you're using
Private _MoveStep As Integer '? I don't know what data type you're using
Public Property PlayerName As String
Get
Return _PlayerName
Eng Get
Set(ByVal value As String)
_PlayerName = value
End Set
End Property
.
. ' Same thing for your other Player properties
.
Public Sub New()
End Sub
Public Sub New(ByVal playerName As String, ByVal position As Integer, ByVal moveStep As Integer)
Me.PlayerName = playerName
Me.Position = position
Me.MoveStep = moveStep
End Sub
Then, to maintain a collection of Players, in an appropriate place in your code:
Dim Players() As Player
(This is quik and dirty mind you! I'd actually create another class to maintain the Players collection and put the SaveData and LoadData methods in this class).
Now, to save your Player data, all you need to do is something like this:
Public Sub SavePlayerData()
Dim sw As New StreamWriter(Path.Combine(Application.StartupPath, "PlayerData.xml"))
Dim xmls As New XmlSerializer(Players.GetType())
xmls.Serialize(sw, Players)
sw.Close()
End Sub
To load that data:
Public Function LoadPlayerData()
Dim sr As New StreamReader(Path.Combine(Application.StartupPath, "PlayerData.xml"))
Dim xmls As New XmlSerializer(Players.GetType())
Players = CType(xmls.Deserialize(sr), Player())
Done! You don't have to do any parsing of lines or data because the Serializer does it all for you!
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
does it need any loop??
cause wat in my mind is the game maybe have 1-4 player, so let said in this round have
3 players
player:1
NAme:A
Position:10
Movestep:2
player:2
NAme:B
Position:8
Movestep:2
player:3
NAme:C
Position:7
Movestep:2
-- so i was thinking to use the x value to loop 3 times since got 3 player
and read 4 line accordinly.... am not sure can it work but i only know a bit on using the readline, i never write it in xml b4..not really understand how it work ..
|
|
|
|
|
campbells wrote: does it need any loop??
Nope. You don't need to worry about how many players are in the file or parsing each and every line. The Serializer takes care of all of this for you.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
do u have more example or article about this xml thing?
|
|
|
|
|
i wonder is i have 3 player i do i read the first line to get how many player at that time???
cause i jsut understand is will recall the player status part but how it know how many times to loop it?
|
|
|
|
|
Your not listening... Doing it using a Serialization method frees you having to loop anything while reading the file. The Serializer takes care of that for you!! All you need to do is check the Bounds of the array to get the number of Players in it after the Players array is recreated.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
sombody was asking about how to do this before and i cant remember where they posted, but i know it was for vb.net so here is the code to get the IP address and port from a TCPClient...ideas came from some other posts on this sight and where modified to work with VB instead of C# and i also added the AddressInfo class...hope this helps someone
=============================================================================
Imports System.Net
Imports System.Net.Sockets
Imports System.Reflection
Public Class NetworkUtils
Public Const kLineEnd = 10
#Region "AddressInfo"
Public Class AddressInfo
Private m_IP As String
Private m_Port As String
Public Sub New()
m_IP = MyIP()
m_Port = "999"
End Sub
Public Sub New(ByVal theIP As String, ByVal thePort As String)
m_IP = theIP
m_Port = thePort
End Sub
Public ReadOnly Property IP() As String
Get
Return m_IP
End Get
End Property
Public ReadOnly Property Port() As String
Get
Return m_Port
End Get
End Property
End Class
#End Region
Public Shared Function AddressInfoFromTCPClient(ByRef theClient As TcpClient) As AddressInfo
Dim theAddress() As String = CType(theClient.GetStream.GetType.GetProperty("Socket", BindingFlags.NonPublic Or BindingFlags.Instance).GetValue(theClient.GetStream, Nothing), Socket).RemoteEndPoint.ToString.Split(":")
Return New AddressInfo(theAddress(0), theAddress(1))
End Function
Public Shared Function MyIP() As String
Return System.Net.Dns.Resolve(System.Net.Dns.GetHostName).AddressList(0).ToString
End Function
End Class
Pablo
|
|
|
|
|
Don't post it here. Noone ever searches the comments and it'll be a couple pages back in a few days...
Write up an article on the technique, commenting on how you did this, what parts of the code do what, why it's a good idea, and post it!! That's what CP is here for!
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
It's a simple questions, when and where do you use try/catch blocks? Does anyone know of an artical that covers the basic dos and don'ts of try/catch block.
|
|
|
|
|
spoodygoon wrote: Does anyone know of an artical that covers the basic dos and don'ts of try/catch block.
Go to the top of your browser screen, and type in try catch into the Search text box, then press the Go button. You'll find many articles.
...Steve
1. quod erat demonstrandum
2. "Give a man a fish and you've fed him for a day. Teach him how to fish and you've fed him for life." I read that somewhere once
(Translation: I'll show you the way, but not write the code for you.)
|
|
|
|
|
It's mainly used to catch/handle Exceptions Especially used when the coding has got interaction with the database connections
"Aim to go where U have never been B4 and Strive to achieve it"
http://groups.yahoo.com/subscribe/dotnetforfreshres
http://himabinduvejella.blogspot.com
|
|
|
|
|
How can i get status how long is the user online, how much did he dll and upload...
<blink>FeRtoll Software.net
------------
E-Mail me
WebPage
|
|
|
|