|
Simon,I use msgbox to show the select node,I found that it got forcus on mouse click,emm...,I means when I click "123",the e.node is really "123",and this time the controls occured.
But I found another question.For example,Panel 2 was on Panel 1,Panel 2 relies on Panel 1.I want when I clicked node 1,Panel 1 should display;when I clicked node 2,Panel 2 should display.Could you tell me how could do this?
Thanks a lot!
|
|
|
|
|
If panel1 is a child of panel2 OR Panel2 is a child of Panel1 you'll never see child panelin your form.
Check the following Code:
Private Sub treeQiaoTi_NodeMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeNodeMouseClickEventArgs) Handles treeQiaoTi.NodeMouseClick
Me.Text = e.Node.Text
If e.Node.Text = "abc" Then
panJieGuan2.Visible = False
Panel1.Visible = True
Panel1.BringToFront()
Else
Panel1.Visible = False
panJieGuan2.Visible = True
panJieGuan2.BringToFront()
End If
End Sub
This is not Necessary yet:
Private Sub treeQiaoTi_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles treeQiaoTi.AfterSelect
End Sub
Use <pre lang="vb"> Visual Basic Code Here.</pre>
|
|
|
|
|
Hi,Aslam,thank you very much!
|
|
|
|
|
Hi friends,
Kindly help me for this.
I have one excel sheet which has only 1 row (first row) which is heading.
I have another excel sheet which has header row and data rows.
I wanted to copy from the second excel sheet to first excel sheet based on the header using vba.
Please help me...
Thanks in Advance!!
Regards,
|
|
|
|
|
Even tou ur problem was not clear i tried to help you with what i have understood.
You want to copy a sheet from a sheet, if a sheet has three columns below is the code.
Dim i As Integer
i = 1
While Trim(sheet2.Cells(i, 1)) <> ""
sheet1.cells(i,1)=sheet2.cells(i,1)
sheet1.cells(i,2)=sheet2.cells(i,2)
sheet1.cells(i,3)=sheet2.cells(i,3)
i=i+1
wend
If you want to keep the header as it is in sheet1 and want to copy the whole thing next to it, below is the code:
Dim i As Integer
i = 1
While Trim(sheet2.Cells(i, 1)) <> ""
sheet1.cells(i+1,1)=sheet2.cells(i,1)
sheet1.cells(i+1,2)=sheet2.cells(i,2)
sheet1.cells(i+1,3)=sheet2.cells(i,3)
i=i+1
wend
cheers
'S wayez
'http://wayezquotes.blogspot.com
|
|
|
|
|
if you dont want to disturb both the header then
i=2
if you want to compare headers of both
if sheet1.cells(1,1)=sheet2.cells(1,1) then
Dim i As Integer
i = 2
While Trim(sheet2.Cells(i, 1)) <> ""
sheet1.cells(i,1)=sheet2.cells(i,1)
sheet1.cells(i,2)=sheet2.cells(i,2)
sheet1.cells(i,3)=sheet2.cells(i,3)
i=i+1
wend
End if
|
|
|
|
|
Hi,
Thank you so much for replying me..
but i wanted to copy data from one excel file to another excel file...
example in Excel file1, Sheet1 I have data for Emp Id, Emp Name etc.,
I have Excel file2, Sheet1 with only the headers in the first row like Emp Id, Emp Name ...etc..Which is exists some path in the hard drive.
When I open Excel file1 and clicking some button, the data in the Excel file1 sheet1 should go to the Excel file2 sheet1 under approximate columns...
Hope its understandable....
Kindly Reply....
Thanks lot again..
Regards,
|
|
|
|
|
Hi,
it's quite simple as long as the columns of both workbooks are consistent, i.e. if the first column of Workbook1.WorkSheet1 has to go to the first column of Workbook2.Worksheet1, etc. The following snippet works and can give you a first idea:
Sub CopyToTarget()
Dim tgt As Excel.Workbook
Dim target As String
Dim rng As Range
' define the range to copy here
' with End(xlDown) you catch all the rows as long as there are no empty cells.
Set rng = ActiveSheet.Range(Cells(2, 1), Cells(2, 1).End(xlDown))
' open the target workbook as object; in this case the workbook has to exist already!
Set tgt = Application.Workbooks.Open("D:\Target.xls")
' copy the range to the required cell
rng.Copy tgt.Worksheets("Tabelle1").Cells(2, 1)
' save and close the target workbook
tgt.Save
tgt.Close
' delete objects that are no longer needed
Set rng = Nothing
Set tgt = Nothing
End Sub If you have to identify the right column first, use the ranges method 'find' to determine the cell where you want to copy the data. In VBA, you will want to use IntelliSense as much as you can - it really helps you to find your way!
|
|
|
|
|
Hi Michael,
Thanks a lot!!
Its working....but yes as u said..the sequence of the columns will not be simillar as per the source work book...some time the target workbook has more compare to source workbook...now i want to compare the column names and if matching then copy its range under that column...
Thanks again..really its great help...
Regards,
Priya
|
|
|
|
|
Good Priya jii!
As michael said but if you want to check with headers Just check the range in target sheet and compare to data sheet if exists paste.
if ActiveSheet.Range(Cells(1, 1)="Emp Num" then
Set rng = ActiveSheet.Range(Cells(2, 1), Cells(2, 1).End(xlDown))
Set tgt = Application.Workbooks.Open("D:\Target.xls")
rng.Copy tgt.Worksheets("Tabelle1").Cells ' tgt.Save
tgt.Close
end if
|
|
|
|
|
If you want to keep it even more flexible, you rather use 'find' - in case your EmpNum stands in a different column. Here's the modified idea, also checking for non existing header as Ahmed assumed. You can extend it in many different ways.
Sub CopyToTarget()
Dim tgt As Excel.Workbook
Dim rng As Range
Dim srcHeader As Range
Dim tgtHeader As Range
Dim dataCol As Integer
' define the range to copy here, supplying the column no you wish to copy
' with End(xlDown) you catch all the rows as long as there are no empty cells.
dataCol = 1
Set srcHeader = ActiveSheet.Cells(1, dataCol)
Set rng = srcHeader.Range(Cells(2, dataCol), Cells(2, dataCol).End(xlDown))
' open the target workbook as object; in this case the workbook has to exist already!
Set tgt = Application.Workbooks.Open("D:\Target.xls")
' find the header of the given dataCol in row 1 of the target worksheet
Set tgtHeader = tgt.Worksheets("Table1").Rows(1).EntireRow.Find(srcHeader.Value)
' copy the range to the required cell
' if not found then notice the user
If tgtHeader Is Nothing Then
MsgBox "Header not found in target workbook."
Else
rng.Copy tgt.Worksheets("Table1").Cells(2, tgtHeader.Column)
End If
' save and close the target workbook
tgt.Save
tgt.Close
' delete objects that are no longer needed
Set rng = Nothing
Set srcHeader = Nothing
Set tgtHeader = Nothing
Set tgt = Nothing
End Sub Maybe you google for samples of the Range object, they might even inspire you .
|
|
|
|
|
Hi Priya,
regarding your question from direct mail, how you should re-arrange the colunms, I want to give you a first idea again - not knowing if it's the best way ever, but it seems simple and pragmatic:
Sub ReArrange()
Dim strHeaders() As String
Dim sortOrder As String
Dim i As Integer
' define how the columns / headers are to be arranged
sortOrder = "EmpID,EmpName,EmpSalary"
' read the string into an array
strHeaders = Split(sortOrder, ",")
' loop through the array
For i = LBound(strHeaders) To UBound(strHeaders)
' take care: i will be 0 first (array index starting with 0)
' so you can't assign i to a colunm --> i + 1 is fine
MsgBox "Header of column " & i + 1 & " = " & strHeaders(i)
' here you find the respective header and copy your headers and/or data.
' I guess you can adapt the code sample from before already, can you?
Next
End Sub Hope that helps you - and don't forget to vote !
|
|
|
|
|
Hi Michael,
Thanks. Yes the one sheet which i have is so complicated format of row and column and data too...its not structured...So I need more effort for this to get done..Let me try and post if struckup inbetween...
Still I manage to do, but the code I writing is becoming so lengthy ...
Thanks again.
Regards,
Priya.
|
|
|
|
|
If your source data are not structured then what I suggested doesn't make a lot of sense. It might be worth re-organizing your sheet (if possible) OR using range names. You can then refer to named range objects, e.g. Range("myCell") and do what ever with them. If it's so complicated and unstructured, did you already think about dropping the VBA idea and just referencing the respective cells from the (structured) target worksheet?
If you don't get forward or too irritated then feel free to send the workbook to my private address.
Regards,
Michael
|
|
|
|
|
Hi there. I have a login on my vb.net application. It is using the Joomla database for user management and integration to my website.
However i have hit a problem. The joomla passwords are hashed as MD5 and salted with 32 characters. It looks like this hashpassword:salt
The colon splits the password with the salt. Im just struggling to find out how to retrieve the salt and append it to the password.
So far i have this:
Private Sub BtnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnlogin.Click
Dim myCommand As New MySqlCommand
Dim myAdapter As New MySqlDataAdapter
Dim myData As MySqlDataReader
'txtEmail.Text.Replace("'", "\'") BoxPassword.Text.Replace("'", "\'")
Dim SQL As String
'Our MySQL Query
Dim Email As String = TxtEmail.Text.Replace("'", "\'")
Dim password = (getMD5Hash(BoxPassword.Password + ":"))
SQL = "SELECT * FROM `jos_users` WHERE `username` = '" + Email + "' AND `password` = '" + Password + "'"
Label1.Content = BoxPassword.Password
myCommand.Connection = conn
myCommand.CommandText = SQL
myAdapter.SelectCommand = myCommand
Try
'Try to execute the query
myData = myCommand.ExecuteReader()
myData.Read()
If myData.HasRows = 0 Then 'Checkes if a row with the email and password exist.
'If no outputs this:
notifyicon.ShowBalloonTip(3000, "Warning User", "The Email Address and Password that you entered dont match!", Avalon.Windows.Controls.NotifyBalloonIcon.Warning)
Txtwrongpass.Content = "The Email Address and Password that you entered dont match!"
myData.Close()
Else
'if yes outputs this:
'notifyicon.ShowBalloonTip(3000, "Welcome " + myData.GetString("fname") + " " + myData.GetString("lname"), "You have sucessfully logged into RemindMe", Avalon.Windows.Controls.NotifyBalloonIcon.Warning)
Dim loPage1 As New user
loPage1.Background = Brushes.Gray
Me.Content = loPage1
myData.Close()
End If
Catch ex As MySqlException
'If fail outputs MySQL Error
MsgBox(ex.Message)
End Try
End Sub
As you may see if have hashed the password with md5 and attached the ":" colon but i dont know how to retrieve the password.
Any help would be great thanks
modified on Sunday, July 11, 2010 3:34 PM
|
|
|
|
|
In the Joomla Admin Console, on the Global Configuration / System settings page, there is a Secret Word listed, is this not the salt?
|
|
|
|
|
Sorry i should explain better. When you register a new user with joomla it adds a randomly generated salt to the md5 password. so the password in the password field looks like hash:salt (seperated by a colon in the database)
I think this php code helps. I don't know php that well but well enough to read it.
<form action='login.php' method='post' name='login'>
<b>User:<b> <input type=text name='username' maxlength=15 width=18><br/>
<b>Password:<b> <input type=password name='password' maxlength=15 width=18><br/>
<input type=submit value='Login'>
</form>
<?php
$dbaddress='localhost'; $dbuser='root'; $dbpass='root'; $dbname='yourdatabase';
$dbcnx = mysql_connect($dbaddress,$dbuser,$dbpass)
or die("Could not connect: " . mysql_error());
mysql_select_db($dbname, $dbcnx) or die ('Unable to select the database: ' . mysql_error());
$query = mysql_query("select password from jos_users where username = \"" . $_POST["username"] . "\"")
or die("Unable to validate login and password with the database:" . mysql_error());
$result = mysql_fetch_array($query);
$result = $result[0];
$parts = explode( ':', $result);
if (count($parts) < 2) $new_password = md5($_POST["password"]);
else {
$salt = $parts[1];
$new_password = md5($_POST["password"] . $salt) . ":" . $salt;
}
if ($new_password != $result)
{
echo "no login";
}
else
{
echo "successful validation";
}
?>
Thanks for replying,
Robbie.
|
|
|
|
|
Ive been researching for ages but maybe this can help anyone. Similar than above and kind of helps me in away.
$part = explode(":",$password);
$salt = $part[1];
$encrypted_password = md5($mypassword . $salt).":".$salt;
;
So maybe it works by making my vb.net app read the database, get the password and split the password into 2 parts with the :(colon) in the password. Then encrypt the password and add the salt to the password.
However now i think i have the theory, i have no idea how to implement it correctly. Can anyone give a basic example instead please?
Any help is great appreciated,
Robbie.
|
|
|
|
|
Looking at both sets of code, it looks like the md5 is generated from a combination of the password and the salt; then the salt is appended to the md5.
The first bunch of code does a split (expand) on the colon, and uses that to determine if the password has been salted or not. This has maybe been done to cater for an upgrade in Joomla security, but I don't know the history.
It would be better to see the code that is used to register a new user,to work out what they are doing. I'll maybe have a look later.
In the meantime, i am starting with the known values and seeing if i can recreate the stored value in the database.
|
|
|
|
|
Ok. Thanks for replying. It's really annoying me. Im trying to think and it's like when you get writers block. Theres nothing there. Like a head of compressed air.
|
|
|
|
|
I just had a thought.
You say you are trying to retrieve the password?
That won't be possible. Its been hashed with a one way algorithm - md5
All you will be able to do is a comparison for authentication purposes. i.e. provide a password and hash/salt it and then compare with the stored value.
|
|
|
|
|
Ah right i started like that at first but somebody said somthing different.
So still stuck. If the salt is randomly generated then how can i hash/salt the password then compare? The password has been hashed to md5 but the salting i can't do.
Any ideas?
Thanks for your time Dave.
|
|
|
|
|
because the salt is stored alongside the password (after the : )
1) user provides username and password;
2) use username to recover the password fieldvalue from the database table
3) extract the salt from result #2
4) use the password in #1 and the salt in #3 combine and hash to give password hash value
5) extract the hashed password from #2
6) compare #4 with #5 to validate
however, without looking at the php code used in joomla, can't say for sure thats what they are doing, would need to spend more time looking, maybe have a look tomorrow night, away to call it quits, as got an early start tomorrow.
Post how you get on, and i will look again hopefully tomorrow.
Dave
Don't forget to rate messages!Find Me On: Web| Facebook| Twitter| LinkedInWaving? dave.m.auld[at]googlewave.com
modified on Monday, July 12, 2010 2:34 AM
|
|
|
|
|
That sounds OK to me.
|
|
|
|
|
Don't know how you are getting on, but i did some digging in the original joomla distro today, to find out what they do.
As a starting point i wanted to see how they added the admin user to the database during the install and from that it would point me to the code libraries used to do the encryption and salt generation etc.
If you take a look at the installation\installer\helper.php file you will see the createAdminUser() method, and you can see the helper functions being called, namely genRandomPassword() , getCryptedPassword() . The interesting thing to note is the genRandomPassword is also used to generate the necessary random salts.
These methods are found in the library located at; libraries\joomla\user\helper.php along with a couple of others used internally. without knowing the ins and outs of php, the code is pretty easy to follow, and you should be able come up with suitable code to allow vb integration with the joomla db.
hope that heads you off in the right direction now.
|
|
|
|
|