|
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
|
|
|
|
|
johnny1963 wrote: i can't make it working because
specialcase is not declare
Oh come on, try using your brain this morning! Specialcase is just a placeholder for the boolean condition that you already have,
VB x = 95 AndAlso e.delta = -120
c# x == 95 && e.delta == -120
Also you will need to subclass the combobox class to override the method.
Alan.
|
|
|
|
|
Hi Alan i have the right code from Johan Hakkesteegt thanks for your help.
|
|
|
|
|
I have below macro which will retrieve Microsoft excel password.
But it will not retrive word template password
can anyone help out please ?
Public Sub AllInternalPasswords()
' Breaks worksheet and workbook structure passwords. Bob McCormick
' probably originator of base code algorithm modified for coverage
' of workbook structure / windows passwords and for multiple passwords
'
' Norman Harker and JE McGimpsey 27-Dec-2002 (Version 1.1)
' Modified 2003-Apr-04 by JEM: All msgs to constants, and
' eliminate one Exit Sub (Version 1.1.1)
' Reveals hashed passwords NOT original passwords
Const DBLSPACE As String = vbNewLine & vbNewLine
Const AUTHORS As String = DBLSPACE & vbNewLine & _
"Adapted from Bob McCormick base code by" & _
"Norman Harker and JE McGimpsey"
Const HEADER As String = "AllInternalPasswords User Message"
Const VERSION As String = DBLSPACE & "Version 1.1.1 2003-Apr-04"
Const REPBACK As String = DBLSPACE & "Please report failure " & _
"to the microsoft.public.excel.programming newsgroup."
Const ALLCLEAR As String = DBLSPACE & "The workbook should " & _
"now be free of all password protection, so make sure you:" & _
DBLSPACE & "SAVE IT NOW!" & DBLSPACE & "and also" & _
DBLSPACE & "BACKUP!, BACKUP!!, BACKUP!!!" & _
DBLSPACE & "Also, remember that the password was " & _
"put there for a reason. Don't stuff up crucial formulas " & _
"or data." & DBLSPACE & "Access and use of some data " & _
"may be an offense. If in doubt, don't."
Const MSGNOPWORDS1 As String = "There were no passwords on " & _
"sheets, or workbook structure or windows." & AUTHORS & VERSION
Const MSGNOPWORDS2 As String = "There was no protection to " & _
"workbook structure or windows." & DBLSPACE & _
"Proceeding to unprotect sheets." & AUTHORS & VERSION
Const MSGTAKETIME As String = "After pressing OK button this " & _
"will take some time." & DBLSPACE & "Amount of time " & _
"depends on how many different passwords, the " & _
"passwords, and your computer's specification." & DBLSPACE & _
"Just be patient! Make me a coffee!" & AUTHORS & VERSION
Const MSGPWORDFOUND1 As String = "You had a Worksheet " & _
"Structure or Windows Password set." & DBLSPACE & _
"The password found was: " & DBLSPACE & "$$" & DBLSPACE & _
"Note it down for potential future use in other workbooks by " & _
"the same person who set this password." & DBLSPACE & _
"Now to check and clear other passwords." & AUTHORS & VERSION
Const MSGPWORDFOUND2 As String = "You had a Worksheet " & _
"password set." & DBLSPACE & "The password found was: " & _
DBLSPACE & "$$" & DBLSPACE & "Note it down for potential " & _
"future use in other workbooks by same person who " & _
"set this password." & DBLSPACE & "Now to check and clear " & _
"other passwords." & AUTHORS & VERSION
Const MSGONLYONE As String = "Only structure / windows " & _
"protected with the password that was just found." & _
ALLCLEAR & AUTHORS & VERSION & REPBACK
Dim w1 As Worksheet, w2 As Worksheet
Dim i As Integer, j As Integer, k As Integer, l As Integer
Dim m As Integer, n As Integer, i1 As Integer, i2 As Integer
Dim i3 As Integer, i4 As Integer, i5 As Integer, i6 As Integer
Dim PWord1 As String
Dim ShTag As Boolean, WinTag As Boolean
Application.ScreenUpdating = False
With ActiveWorkbook
WinTag = .ProtectStructure Or .ProtectWindows
End With
ShTag = False
For Each w1 In Worksheets
ShTag = ShTag Or w1.ProtectContents
Next w1
If Not ShTag And Not WinTag Then
MsgBox MSGNOPWORDS1, vbInformation, HEADER
Exit Sub
End If
MsgBox MSGTAKETIME, vbInformation, HEADER
If Not WinTag Then
MsgBox MSGNOPWORDS2, vbInformation, HEADER
Else
On Error Resume Next
Do 'dummy do loop
For i = 65 To 66: For j = 65 To 66: For k = 65 To 66
For l = 65 To 66: For m = 65 To 66: For i1 = 65 To 66
For i2 = 65 To 66: For i3 = 65 To 66: For i4 = 65 To 66
For i5 = 65 To 66: For i6 = 65 To 66: For n = 32 To 126
With ActiveWorkbook
.Unprotect Chr(i) & Chr(j) & Chr(k) & _
Chr(l) & Chr(m) & Chr(i1) & Chr(i2) & _
Chr(i3) & Chr(i4) & Chr(i5) & Chr(i6) & Chr(n)
If .ProtectStructure = False And _
.ProtectWindows = False Then
PWord1 = Chr(i) & Chr(j) & Chr(k) & Chr(l) & _
Chr(m) & Chr(i1) & Chr(i2) & Chr(i3) & _
Chr(i4) & Chr(i5) & Chr(i6) & Chr(n)
MsgBox Application.Substitute(MSGPWORDFOUND1, _
"$$", PWord1), vbInformation, HEADER
Exit Do 'Bypass all for...nexts
End If
End With
Next: Next: Next: Next: Next: Next
Next: Next: Next: Next: Next: Next
Loop Until True
On Error GoTo 0
End If
If WinTag And Not ShTag Then
MsgBox MSGONLYONE, vbInformation, HEADER
Exit Sub
End If
On Error Resume Next
For Each w1 In Worksheets
'Attempt clearance with PWord1
w1.Unprotect PWord1
Next w1
On Error GoTo 0
ShTag = False
For Each w1 In Worksheets
'Checks for all clear ShTag triggered to 1 if not.
ShTag = ShTag Or w1.ProtectContents
Next w1
If ShTag Then
For Each w1 In Worksheets
With w1
If .ProtectContents Then
On Error Resume Next
Do 'Dummy do loop
For i = 65 To 66: For j = 65 To 66: For k = 65 To 66
For l = 65 To 66: For m = 65 To 66: For i1 = 65 To 66
For i2 = 65 To 66: For i3 = 65 To 66: For i4 = 65 To 66
For i5 = 65 To 66: For i6 = 65 To 66: For n = 32 To 126
.Unprotect Chr(i) & Chr(j) & Chr(k) & _
Chr(l) & Chr(m) & Chr(i1) & Chr(i2) & Chr(i3) & _
Chr(i4) & Chr(i5) & Chr(i6) & Chr(n)
If Not .ProtectContents Then
PWord1 = Chr(i) & Chr(j) & Chr(k) & Chr(l) & _
Chr(m) & Chr(i1) & Chr(i2) & Chr(i3) & _
Chr(i4) & Chr(i5) & Chr(i6) & Chr(n)
MsgBox Application.Substitute(MSGPWORDFOUND2, _
"$$", PWord1), vbInformation, HEADER
'leverage finding Pword by trying on other sheets
For Each w2 In Worksheets
w2.Unprotect PWord1
Next w2
Exit Do 'Bypass all for...nexts
End If
Next: Next: Next: Next: Next: Next
Next: Next: Next: Next: Next: Next
Loop Until True
On Error GoTo 0
End If
End With
Next w1
End If
MsgBox ALLCLEAR & AUTHORS & VERSION & REPBACK, vbInformation, HEADER
End Sub
|
|
|
|
|
There is no way to modify this to work with Word. It's (very) specifically written to work only on Excel workbooks and, according to the comments, doesn't even reveal the plaintext password, but the hashed version of it.
Noone is going to help you write a tool to crack passwords. Period.
|
|
|
|
|