6 Replies - 5512 Views - Last Post: 27 March 2009 - 09:56 AM Rate Topic: -----

#1 sickles2533   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 26-March 09

declaring a function

Posted 27 March 2009 - 12:54 AM

when I try to run this in vb it is processing an error GetScore is not declared I am very new to c# any suggestions would be greatly app. thanks

System
Module TestScore
	Sub main()
		Dim value As Long
		Console.WriteLine("enter score: ")
		value = Convert.ToDouble(Console.ReadLine())
		'CheckScore(value)
		Console.WriteLine("The current score is {0} ", GetScore())

	End Sub
	Public Class scores
		Private m_highscore As Long

		Private Shared m_initialscore As Long = 100
		Public Sub New()
			m_highscore = m_initialscore
		End Sub

		Public Function GetScore()
			Return m_highscore
		End Function

		Public Function CheckScore(ByVal score As Long)
			If score > m_highscore Then
				SetScore(score)
			Else
				GetScore()
			End If
		End Function

		Private Function SetScore(ByVal score As Long)
			m_highscore = score
		End Function
	End Class
End Module



Mod Edit: Please use code tags when posting your code. Code tags are used like so => :code:

Thanks,
PsychoCoder :)

Is This A Good Question/Topic? 0
  • +

Replies To: declaring a function

#2 b.ihde   User is offline

  • D.I.C for life
  • member icon

Reputation: 45
  • View blog
  • Posts: 1,070
  • Joined: 29-September 08

Re: declaring a function

Posted 27 March 2009 - 01:05 AM

Hello and welcome to DreamInCode!

Well, this is the C# section, your post should be moved to vb..
Please post your complete errormessage, if you can :)

Thanks

Ben Ihde
Was This Post Helpful? 0
  • +
  • -

#3 maj3091   User is offline

  • D.I.C Lover
  • member icon

Reputation: 330
  • View blog
  • Posts: 1,998
  • Joined: 26-March 09

Re: declaring a function

Posted 27 March 2009 - 02:22 AM

Hi,

I agree with Ben, your question is slightly confusing as you refer to VB and C#.

Looking briefly at your code, would you not need to instantiate the Scores class to call the function?

Mark
Was This Post Helpful? 0
  • +
  • -

#4 sickles2533   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 26-March 09

Re: declaring a function

Post icon  Posted 27 March 2009 - 09:10 AM

i am fairly new to vb any suggestions are app. I am trying to get it to show the default score if the score entered is not greater than the default score
i am getting the error Error 1 Argument not specified for parameter 'score' of 'Private Sub SetScore(score As Long)'.


If score > m_highscore Then
SetScore(score)
Else : SetScore()
Imports System
Module TestScore
	Sub main()
		Dim value As Long
		Console.WriteLine("enter score: ")
		value = Convert.ToInt64(Console.ReadLine())
		Dim s As New scores
		s.CheckScore(value)
		Console.WriteLine("Gongrats you have the new high score {0} ", s.GetScore())

	End Sub

End Module

Public Class scores
	Private m_highscore As Long

	Private Shared m_initialscore As Long = 100
	Public Sub New()
		m_highscore = m_initialscore
	End Sub

	Public Function GetScore() As Long
		Return m_highscore
	End Function

	Public Function CheckScore(ByVal score As Long) As Long
		If score > m_highscore Then
			SetScore(score)
		Else : SetScore()
		End If
		Return GetScore()
	End Function

	Private Sub SetScore(ByVal score As Long)
		m_highscore = score
	End Sub
End Class



Mod Edit: Please use code tags when posting your code. Code tags are used like so => :code:

Thanks,
PsychoCoder :)
Was This Post Helpful? 0
  • +
  • -

#5 PsychoCoder   User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1659
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: declaring a function

Posted 27 March 2009 - 09:13 AM

The reason for this is in your Else you are calling SetScore() without passing it the score parameter it's looking for
Was This Post Helpful? 0
  • +
  • -

#6 PsychoCoder   User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1659
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: declaring a function

Posted 27 March 2009 - 09:18 AM

Moved to VB.NET

Topics merged, please don't create duplicate topics :)
Was This Post Helpful? 0
  • +
  • -

#7 sickles2533   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 26-March 09

Re: declaring a function

Posted 27 March 2009 - 09:56 AM

View PostPsychoCoder, on 27 Mar, 2009 - 08:13 AM, said:

The reason for this is in your Else you are calling SetScore() without passing it the score parameter it's looking for


when I pass it correctly it prints out try again and new score thanks for the sugg
If score > m_highscore Then
			SetScore(score)
		Else : score = m_highscore
			Console.WriteLine("try again")




Imports System
Module TestScore
	Sub main()
		Dim value As Long
		Console.WriteLine("enter score: ")
		value = Convert.ToInt64(Console.ReadLine())
		Dim s As New scores
		s.CheckScore(value)
		Console.WriteLine("Gongrats you have the new high score {0}", s.GetScore())
	End Sub

End Module

Public Class scores
	Private m_highscore As Long

	Private Shared m_initialscore As Long = 100
	Public Sub New()
		m_highscore = m_initialscore
	End Sub

	Public Function GetScore() As Long
		Return m_highscore
	End Function

	Public Function CheckScore(ByVal score As Long) As Long
		If score > m_highscore Then
			SetScore(score)
		Else : score = m_highscore
			Console.WriteLine("try again")
		End If
		Return GetScore()
	End Function

	Private Sub SetScore(ByVal score As Long)
		m_highscore = score
	End Sub
End Class
















View Postsickles2533, on 27 Mar, 2009 - 08:55 AM, said:

View PostPsychoCoder, on 27 Mar, 2009 - 08:13 AM, said:

The reason for this is in your Else you are calling SetScore() without passing it the score parameter it's looking for


when I pass it correctly it prints out try again and new score thanks for the sugg
if the score is below 100 i just want it to say try again
If score > m_highscore Then
			SetScore(score)
		Else : score = m_highscore
			Console.WriteLine("try again")




Imports System
Module TestScore
	Sub main()
		Dim value As Long
		Console.WriteLine("enter score: ")
		value = Convert.ToInt64(Console.ReadLine())
		Dim s As New scores
		s.CheckScore(value)
		Console.WriteLine("Gongrats you have the new high score {0}", s.GetScore())
	End Sub

End Module

Public Class scores
	Private m_highscore As Long

	Private Shared m_initialscore As Long = 100
	Public Sub New()
		m_highscore = m_initialscore
	End Sub

	Public Function GetScore() As Long
		Return m_highscore
	End Function

	Public Function CheckScore(ByVal score As Long) As Long
		If score > m_highscore Then
			SetScore(score)
		Else : score = m_highscore
			Console.WriteLine("try again")
		End If
		Return GetScore()
	End Function

	Private Sub SetScore(ByVal score As Long)
		m_highscore = score
	End Sub
End Class















Was This Post Helpful? 0
  • +
  • -

Page 1 of 1