|
an example of my code is this
Sub LoadWordArray()
strWordListArray(0) = "ELEPHANT"
strWordListArray(1) = "CARRIAGE"
strWordListArray(2) = "ENVELOPE"
strWordListArray(2) = "ENVELOPE"
strWordListArray(2) = "ENVELOPE"
strWordListArray(3) = "PRESIDENT"
strWordListArray(4) = "ELLIPTICAL"
I want to have when the word elephant is being guessed a box or something that gives a hint to the person guessing that is i a very large gray anamal. You know something like that, it will be different for every word but thats the idea
|
|
|
|
|
OK, so you need to store the hint to go with each word, so probably an array of a struct instead ( word and hint(s) ). Then you need to decide how and when to display them
Christian Graus
Driven to the arms of OSX by Vista.
"I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )
|
|
|
|
|
Can you give me an example? Like I said I am new at this so I am not really sure what you mean. Thank you
|
|
|
|
|
What Christian means is instead of using a string array that you now have to store your words, create a structure that contains both the word and a hint string, and make an array of that structure.
HTH
|
|
|
|
|
Well, I gave you all the keywords you should need. Do you not know how to create a class or a struct ?
class HangmanWord
{
public string word;
public string hint;
}
is fine.
Beyond that, your task is not specific enough to give any sort of hint. You need to decide when and how to show a hint.
Christian Graus
Driven to the arms of OSX by Vista.
"I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )
|
|
|
|
|
another best simple way is to do a array with 2 dimensions:
strArray(1,1)= "Elephant", ""A Large Big Grey Animal"
then you assign it to you output to display the Hint(which will be your second dimension)
|
|
|
|
|
The error I get is "Timespan can not be converted to a string".
I did a lot of reading and experimenting on this problem.
My weakness is not understanding the methodology of timespan and parse-ing.
--------------------------------
Public Class Form1
Dim NowIs As Date
Dim NowWas As Date = Now
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
NowIs = Now
TextBox1.Text = NowIs - NowWas
NowWas = NowIs
End Sub
End Class
--------------------------------------
The idea is for the text box to indicate the amount of time passed, in minutes.
Hours could elapse between events.
Thanks in advance to all those who help.
Steve B.
modified on Thursday, April 23, 2009 5:00 PM
|
|
|
|
|
Your problem lies at this line:
Laser Steve wrote:
TextBox1.Text = NowIs - NowWas
When you subtract two Dates, you get a TimeSpan structure. TextBox1.Text is a String type. TimeSpan and String aren't directly equatable. If you want to get the TimeSpan in minutes, use this instead:
TextBox1.Text = (NowIs - NowWas).TotalMinutes
It's really messy (if something goes wrong creating the TimeSpan, you get an ugly error. It also looks ugly), but it works. If you want to learn more about date and time, look into these links:
TimeSpan documentation
DateTime documentation
Date and time format strings (used in parsing methods as well as formatting, so these are important)
|
|
|
|
|
Hi, I have example here on how to get the difference of date and time in C#.
Please follow these step:
Step: 1
Create a timer then set the interval to 10 and enabled to true.
Step: 2
Create 3 Label. Label1,Label2,Label3.
Step: 3
Create 2 Datepicker. Name it dtfrom and dtto.
Step: 4
Create a Button1
Then Copy this Code at your form:
private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
{label1.Text = dtfrom.Value.ToString();}
private void timer1_Tick(object sender, EventArgs e)
{label2.Text = string.Format("{0:G}", DateTime.Now);}
private void button1_Click(object sender, EventArgs e)
{
TimeSpan ts = new TimeSpan();
DateTime dt1,dt2 = new DateTime();
dt1 = dtfrom.Value;
dt2 = Convert.ToDateTime(label2.Text);
ts=dt1.Subtract(dt2);
label3.Text = ts.ToString(); //Answer
}
for more information visit this: <a href="http://codeincsharp.blogspot.com/2008/05/how-to-get-date-and-time-difference-in.html">http://codeincsharp.blogspot.com/2008/05/how-to-get-date-and-time-difference-in.html</a>[<a href="http://codeincsharp.blogspot.com/2008/05/how-to-get-date-and-time-difference-in.html" target="_blank" title="New Window">^</a>]
|
|
|
|
|
Try This:
Public Class Form1
Dim NowWas As Date = Now
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox1.Text = Now.Subtract(NowWas).TotalMinutes.ToString
End Sub
End Class
|
|
|
|
|
Try TextBox1.Text = Convert.ToString(NowIs-NowWas)
|
|
|
|
|
how can i go from the last item in a combobox to the first item.
With the folowing code i go always to the second item.
Private Sub ComboBox1_MouseWheel(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ComboBox1.MouseWheel
Dim x As Integer
x = ComboBox1.SelectedIndex.ToString
If x = 95 AndAlso e.delta = -120 Then
ComboBox1.Text = ComboBox1.Items(0).ToString()
End If
End Sub
so i tried a lot of things but i gives me always the second item.
thanks.
|
|
|
|
|
If you want the first item in the combo box to be selected, can't you just use:
ComboBox1.SelectedIndex = 0
?
|
|
|
|
|
no even that gives the second item
|
|
|
|
|
Are you sure that:
A) this code block is being executed
B) there isn't any other code which sets the selected index of the combo box after this code block.
I'm guessing that the index is being set elsewhere because ComboBox1.SelectedIndex = 0 will select the first item.
|
|
|
|
|
Yes i am sure
i wrote
if combobox.selectedindex = 19 then
combobox.selectedindex = 0
end if
and this gives me the second item
i had tried that before thats why i asked it here.
i would say try it.
|
|
|
|
|
Ah, I have just tested and found that after the selected index of the combo box is set, the mouse wheel movement is actioned. That is, if you scroll downwards, then after setting the combobox to index 0, the scroll down is done (but if you scroll upwards then it is fine).
The only way I can think of around this (which isn't very pretty) is to add and event handler after setting the index of the combo box. Something like:
Private Sub ComboBox1_MouseWheel(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ComboBox1.MouseWheel
If ComboBox1.selectedindex = 19 then
AddHandler ComboBox1.SelectedIndexChanged, AddressOf SetIndex
End If
End Sub
Private Sub SetIndex(ByVal sender As Object, ByVal e As System.EventArgs)
ComboBox1.SelectedIndex = 0
RemoveHandler ComboBox1.SelectedIndexChanged, AddressOf test
End Sub
Like I said, not a pretty solution so maybe someone else has other ideas?
modified on Wednesday, April 22, 2009 1:47 PM
|
|
|
|
|
your solution doesn't work because of the word "test".
Test is not decleared.
if i change it to setindex in run the project then the first item does not come it stays at the last item.
sorry couldn't response earlier
thanks
|
|
|
|
|
the only ting i can do is ad an emtpty string as last item
and then
If ComboBox1.SelectedIndex = 20 Then
ComboBox1.SelectedIndex = 0
20 is the last item as a empty string
that works but it's like you said even not so nice.
|
|
|
|
|
I figured out a solution:
dim i as integer
Private Sub ComboBox1_MouseWheel(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ComboBox1.MouseWheel
Try
If ComboBox1.SelectedIndex = ComboBox1.Items.Count - 1 And e.Delta = -120 Then
i = ComboBox1.SelectedIndex
ComboBox1.SelectedIndex = 0
Else
Me.OnMouseWheel(e)
End If
Catch ex As Exception
ComboBox1.SelectedIndex = 0
End Try
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
If i = ComboBox1.Items.Count - 1 And ComboBox1.SelectedIndex = 1 Then
ComboBox1.SelectedIndex = 0
i = 0
End If
End Sub
It's funny though, how that mouse wheel event only lets you perform actions in between turns (so to speak).
My advice is free, and you may get what you paid for.
modified on Thursday, April 23, 2009 3:22 AM
|
|
|
|
|
thanks eddy that's it
thank you
|
|
|
|
|
You're welcome.
Now you just need to figure how to adapt this to also work when you scroll up
Cheers,
Johan
My advice is free, and you may get what you paid for.
|
|
|
|
|
again thanks johan.
sorry for mistyping your name
|
|
|
|
|
Hi,
How is this happening then?
Setting the Text property of the combobox implicity changes the SelectedIndex property. Therefore your code must set SelectedIndex to 0.
ComboBox1.Text = ComboBox1.Items(0).ToString()
But what happens next? The default mouse wheel handling then increments the SelectedIndex from 0 to 1 to give the observed effect of always getting the second item selected.
The solution must be to disable the default handling for the one special case of wrapping the index from bottom to top and you’ll have to do this via an override of the OnMouseWheel method.
In c# I'd do this
protected override void OnMouseWheel(MouseEventArgs e) {
if (specialcase) {
SelectedIndex = 0;
} else {
base.OnMouseWheel(e);
}
}
Let me know if this works, as it's a bit of a guess on my part.
Alan.
modified on Wednesday, April 22, 2009 9:33 PM
|
|
|
|
|
i can't make it working because
specialcase is not declare
|
|
|
|