7 Replies - 828 Views - Last Post: 09 June 2008 - 01:53 AM Rate Topic: -----

#1 narmer93  Icon User is offline

  • D.I.C Regular

Reputation: 8
  • View blog
  • Posts: 317
  • Joined: 13-March 08

need some help

Post icon  Posted 24 May 2008 - 04:49 AM

hi i need some help with some codes

first how can i use a timer to make a splash screen appear for few seconds and then disappear and another form appears?

second: whr\en itype the code
[code]textbox1,text=textbox1.text+"something"[code]
the typing curser that shows where will typing be appears in the begining of the textbox
how can i conterl its place?

third :is there a way to stop error messages?

fourth: how can i use a combobox
i mean when i choose a choise in it and press a button
i want a text to be added to a textbox
:wub: :wub:

and for more info
it is not a homework i just want to make some projects for me :wub: :wub:

Is This A Good Question/Topic? 0
  • +

Replies To: need some help

#2 Locke  Icon User is offline

  • Sarcasm Extraordinaire!
  • member icon

Reputation: 516
  • View blog
  • Posts: 5,588
  • Joined: 20-March 08

Re: need some help

Posted 24 May 2008 - 10:20 AM

Well, I don't know about the first or second one...and I don't think there is a way to stop error messages, unless you mean runtime exceptions.

But the fourth problem, I can do.

Private Sub btnSeeText_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSeeText.Click

    txtTextBox.text = cboChoices.text  ' That sets the combo box text to the textbox, if you want to select a choice and set different text, let me (or someone else) know

End Sub

This post has been edited by Locke37: 24 May 2008 - 10:21 AM

Was This Post Helpful? 0
  • +
  • -

#3 CrazyCoder  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 06-November 07

Re: need some help

Posted 03 June 2008 - 05:28 PM

Regarding holding a splash screen:

Private Sub SplashScreen_FormClosing(ByVal sender As Object, _
ByVal e As System.Windows.Forms.FormClosing Event Args) Handles Me.FormClosing
'Hold the form on the screen for approximately 5 seconds before closing.

System.Threading.Thread.Sleep (5000) ' Sleep 5000 milliseconds.

End Sub


As for the error messages, best way to stop them appearing is learning to code properly.
Goodluck :D
Was This Post Helpful? 0
  • +
  • -

#4 robertelder  Icon User is offline

  • New D.I.C Head

Reputation: 5
  • View blog
  • Posts: 30
  • Joined: 06-June 08

Re: need some help

Posted 06 June 2008 - 08:34 AM

narmer93,

#1 Your first question was how to make a splash screen appear for few seconds and then disappear and have another form appear.

I am going to assume that you have a timer (Timer1), and two forms (Form1, Form2). I am also going to assume that you want the splash screen to show up when the application loads. By default, Form1 is the form that will load when the application is launched. To make it easier on myself I will just accept the default and use Form1 as the splash screen.

(If you want to make Form2 be the one that is loaded first and become the splash screen, all you have to do is go into your solution explorer and right click on the Project. Click Properties. In vb2008 a big screen will appear in the work area. The first tab is called Application and there is a button called StartUp Form that you can use to select which ever form you want.)

Place a Timer control on Form1. If the Timer1.Interval property is set to 1, it will tick once every millisecond. Since your question was related to seconds, I would set the interval to 1000 to make your code read easier.
Here is all the code needed for Form1:
Public Class Form1
	Dim intSeconds As Integer

	Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
		Timer1.Interval = 1000
		Timer1.Start()
	End Sub

	Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
		'increment the seconds variable
		intSeconds += 1

		'After 5 seconds, open Form2 and close this form
		If intSeconds = 5 Then
			Form2.Show()
			Me.Visible = False
		End If
	End Sub

End Class



In form2, make sure that when this form (Form2) closes it also closes the invisible Form1. I suggest making this a separate Subroutine, that way it works even when users click on the red X in the Control box of the form.
	Private Sub Form2_Close(ByVal sender As System.Object, ByVal e As System.EventArgs)  _
											Handles Me.FormClosing
		Form1.Close()
	End Sub





#2. Your second question was about changing the position of the cursor in a textbox after changing its text programmatically.

I will assume that you have a button (Button1) and a textbox (Textbox1) on your form.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
		'simulate existing text in the textbox
		TextBox1.Text = "Hello"

		'add new text to the textbox
		TextBox1.Text = TextBox1.Text + " World"

		'give the focus to the textbox
		TextBox1.Focus()

		'where do you want the blinking cursor
		'may be any integer... normally based on something like length of the text though
		TextBox1.Selectionstart = TextBox1.Text.Length - 5

		'how many characters do you want the cursor to select
		TextBox1.SelectionLength = 0

End Sub





#3. Your third question was about how to stop error messages. I'm not quite sure how to answer this one. There are several ways to do this. The best way of course is to write you code so that there aren't any errors. If that is not possible, the next best way is to know what they are and deal with them.

For example, if I have an application that lets users provide input through a textbox, I will add some extra code to make sure that the input is going to work in the program before I let the program try to use it. (see example in my answer for your fourth question). I strongly suggest you look up "TRY... CATCH... FINALLY" as it is the best way to handle any unexpected exceptions that may occur.




#4. Your fourth question was about how to make a textbox show the text from a selected choice in a combobox when a button is pressed.

I will assume you have a combobox(ComboBox1), a textbox (TextBox1), and a button (Button1) on your form (Form1). In order for this to work, there has to be something in the combobox, so I am going to add two items to the combolist when the form loads. When the button is pressed, the textbox will display the text of the item selected in the combobox, or if nothing is selected a message box will appear.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
		ComboBox1.Items.Add("Hello World")
		ComboBox1.Items.Add("Goodbye World")
	End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
		 If ComboBox1.SelectedIndex = -1 Then
			MsgBox("Nothing is selected")
		Else
			TextBox1.Text = ComboBox1.SelectedItem
		End If
End Sub



I hope this has help you.

-Rob
Was This Post Helpful? 0
  • +
  • -

#5 narmer93  Icon User is offline

  • D.I.C Regular

Reputation: 8
  • View blog
  • Posts: 317
  • Joined: 13-March 08

Re: need some help

Posted 06 June 2008 - 08:38 AM

View PostCrazyCoder, on 3 Jun, 2008 - 05:28 PM, said:

Regarding holding a splash screen:

Private Sub SplashScreen_FormClosing(ByVal sender As Object, _
ByVal e As System.Windows.Forms.FormClosing Event Args) Handles Me.FormClosing
'Hold the form on the screen for approximately 5 seconds before closing.

System.Threading.Thread.Sleep (5000) ' Sleep 5000 milliseconds.

End Sub


As for the error messages, best way to stop them appearing is learning to code properly.
Goodluck :D


this code isnt working
any other ideas
Was This Post Helpful? 0
  • +
  • -

#6 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 415
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: need some help

Posted 06 June 2008 - 09:48 AM

Post the code that you have completed so far and we will be happy to help you get it working.
Was This Post Helpful? 0
  • +
  • -

#7 narmer93  Icon User is offline

  • D.I.C Regular

Reputation: 8
  • View blog
  • Posts: 317
  • Joined: 13-March 08

Re: need some help

Posted 08 June 2008 - 01:17 PM

hi i mixed both ideas of these codes
 narmer93,

#1 Your first question was how to make a splash screen appear for few seconds and then disappear and have another form appear.

I am going to assume that you have a timer (Timer1), and two forms (Form1, Form2). I am also going to assume that you want the splash screen to show up when the application loads. By default, Form1 is the form that will load when the application is launched. To make it easier on myself I will just accept the default and use Form1 as the splash screen.

(If you want to make Form2 be the one that is loaded first and become the splash screen, all you have to do is go into your solution explorer and right click on the Project. Click Properties. In vb2008 a big screen will appear in the work area. The first tab is called Application and there is a button called StartUp Form that you can use to select which ever form you want.)

Place a Timer control on Form1. If the Timer1.Interval property is set to 1, it will tick once every millisecond. Since your question was related to seconds, I would set the interval to 1000 to make your code read easier.
Here is all the code needed for Form1:
CODE
Public Class Form1
	Dim intSeconds As Integer

	Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
		Timer1.Interval = 1000
		Timer1.Start()
	End Sub

	Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
		'increment the seconds variable
		intSeconds += 1

		'After 5 seconds, open Form2 and close this form
		If intSeconds = 5 Then
			Form2.Show()
			Me.Visible = False
		End If
	End Sub

End Class 




and

 For Each clsProcess As Process In Process.GetProcesses 
	  If clsProcess.ProcessName.StartsWith(name) Then
			clsProcess.Kill() 
End If  
	Next


to make the following one



Public Class Form1
	Dim intseconds As Integer
	Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
		Timer1.Interval = 1000

 End Sub


	Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

	If Me.Button1.Text = "start" Then
			Button1.Text = "stop"
			Me.Timer1.Start()

		Else
			Button1.Text = "start"
			Me.Timer1.Stop()

		End If

	End Sub

	Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
		intseconds += 1
		If intseconds = Me.TextBox2.Text Then
			For Each clsprocess As Process In Process.GetProcesses

				If clsprocess.ProcessName.StartsWith(Me.TextBox1.Text) Then
					clsprocess.Kill()
				 
				End If
			Next
		End If
	End Sub



the form contains 2 textboxes( one to type the process name and other to type the time in seconds
the problem is that it works only once and when i change the time or the process ,it doesnt work again, i though that i may need to refresh so i made a refresh code, i made
me.refresh()

but there was no one like
timer1.refresh 

so how can i make it work for more than once?
Was This Post Helpful? 0
  • +
  • -

#8 robertelder  Icon User is offline

  • New D.I.C Head

Reputation: 5
  • View blog
  • Posts: 30
  • Joined: 06-June 08

Re: need some help

Posted 09 June 2008 - 01:53 AM

narmer93,

I tried your code out and had the same issue at first. I was setting the textbox2.text = 3 (so I would only have to wait a few seconds before getting results). The first time it worked perfectly. I clicked the Button1 to stop the timer, changed the processname and clicked Button1 again to restart the timer. Nothing happened. Then I realized something... in the timer1_tick subroutine, you have intseconds constantly adding to itself. Button1 does not set intseconds back to 0, so in addition to changing the process name, I would have also had to change the seconds value for it to work.

Try this for your button1 sub:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
		If Me.Button1.Text = "start" Then
			Button1.Text = "stop"
			Me.Timer1.Start()
		Else
			Button1.Text = "start"
			Me.Timer1.Stop()
		End If
		intseconds = 0
End Sub



-Rob
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1