|
If you have XML, you can use SelectSingleNode on an Xmldocument to see if you r node existss.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Been coding for about 3 months now and am currently making a "login" client for myself. I hve created a streamreader and have linked it to a .txt file which is located on my hardrive and i am struggling to get it to read of multiple lines so i can have more than one user. This is the code i have at the moment
Public Class Form1<br />
Dim webe As New ProcessStartInfo()<br />
Dim username1 As New IO.StreamReader("C:\Textfile.txt")<br />
<br />
Private Sub Login_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Login.Click<br />
If Username.Text & Password.Text = username1.ReadToEnd & "lol" Or Username.Text & Password.Text = "Admin" & "admin" Then<br />
StatusStrip.Text = "Welcome " & Username.Text
Thanks In Advance
|
|
|
|
|
Text file suppose to have more than one record there fore you should read the values inside a loop. Please see example below. The shown code sample below suppse to be inside Login_Click procedure
Dim webe As New ProcessStartInfo()
Dim username1 As New IO.StreamReader("C:\Textfile.txt")
Do While NOT UserName.EndOfStream
If UserName1.ReadLine() = UserName.Text.toString & PassWord.Text.ToString Then
'login information exist perform some type of actions
exit do
ElseIf UserName.Text & PassWord.Text = "Admin" & "admin" Then
StatusStrip.text = "WelCome" & userName.Text
End IF
Loop
UserName1.Close()
-- modified at 12:28 Monday 19th March, 2007
What a curious mind needs to discover knowledge is noting else than a pin-hole.
|
|
|
|
|
I added in your code and i seen to be getting this error under the "Username.EndOfReader" 'EndofReader is not a members of the windows.form.textbox'
Another expection i am getting is the "exit loop" is thrwoing an exception, 'exit must be followed by sub, function, property etc etc etc'
I have tried to play about with it but still struggling with working it out.
|
|
|
|
|
Sorry my mistake... Convert .text.toString and then use exit do also Replace EndOfReader with EndOfStream... I apologize...
What a curious mind needs to discover knowledge is noting else than a pin-hole.
|
|
|
|
|
|
JUNETY or anyone else, i have just had to format my pc and when i load up VS05 and my code i keep getting this error when debuging it, i have looked everywhere but it is really baffling me! any help will be appreciated!
Dim username1 As New IO.StreamReader("C:\username.txt")<br />
Dim password1 As New IO.StreamReader("C:\password.txt")<br />
Dim adminun As New IO.StreamReader("C:\adminun.txt")<br />
Dim adminpw As New IO.StreamReader("C:\adminpw.txt")<br />
<br />
<br />
Private Sub Login_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Login.Click<br />
Do While username1.EndOfStream<br />
If username1.ReadLine() = Username.Text.ToString & Password.Text.ToString Then<br />
Exit Do<br />
End If<br />
Loop<br />
username1.Close()<br />
Do While password1.EndOfStream<br />
If username1.ReadLine() = Username.Text.ToString & Password.Text.ToString Then<br />
Exit Do<br />
End If<br />
Loop<br />
password1.Close()<br />
End Sub<br />
ERROR:
System.ObjectDisposedException was unhandled<br />
Message="Cannot read from a closed TextReader."<br />
ObjectName=""<br />
Source="mscorlib"<br />
StackTrace:<br />
at System.IO.__Error.ReaderClosed()<br />
at System.IO.StreamReader.get_EndOfStream()<br />
at WindowsApplication1.Form1.Login_Click(Object sender, EventArgs e) in C:\Users\Brad\Documents\Visual Studio 2005\Projects\SC Login\SC Login\Form1.vb:line 9<br />
at System.Windows.Forms.Control.OnClick(EventArgs e)<br />
at System.Windows.Forms.Button.OnClick(EventArgs e)<br />
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)<br />
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)<br />
at System.Windows.Forms.Control.WndProc(Message& m)<br />
at System.Windows.Forms.ButtonBase.WndProc(Message& m)<br />
at System.Windows.Forms.Button.WndProc(Message& m)<br />
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)<br />
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)<br />
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)<br />
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)<br />
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)<br />
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)<br />
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)<br />
at System.Windows.Forms.Application.Run(ApplicationContext context)<br />
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()<br />
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()<br />
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)<br />
at WindowsApplication1.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81<br />
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)<br />
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)<br />
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()<br />
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)<br />
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)<br />
at System.Threading.ThreadHelper.ThreadStart()
I am on Vista but still cannot see why it is thwoing this exception, I have tried putting the files on desktop etc but still getting "Cannot read from a closed TextReader". Also another problem is that when i click "login" once nothing happens even with other code but when i double click i get the above error!
Thanks
-- modified at 20:36 Tuesday 20th March, 2007
|
|
|
|
|
Because you are making a mistake as follows:
When you close the first stream therefore without reopening it you can't define UserName1 inside the second stream because its closed. Your approach to check username, password, etc. seems not appripriate. I suggest you to reorganize your code.
What a curious mind needs to discover knowledge is noting else than a pin-hole.
|
|
|
|
|
Hello!
Here is my function which opens a XML document and retrieves the value of it. But I am getting an error message because of a null value. It doesn't read the DateInstalled value from the file. What is the error? Thanks.
Private Function GetConfigParameter(ByVal MyKey As String) As String
Dim XmlDocument As New XmlDocument
Dim XmlNode As XmlNode = Nothing
XmlDocument.Load(Environment.CurrentDirectory & "\app.con")
XmlNode = XmlDocument.DocumentElement.SelectSingleNode("//configuration/AppDefaultValues/add[@key=""" & MyKey & """]")
GetConfigParameter = XmlNode.Attributes.GetNamedItem("value").Value
XmlDocument = Nothing
End Function
-- modified at 12:02 Monday 19th March, 2007
What a curious mind needs to discover knowledge is noting else than a pin-hole.
|
|
|
|
|
Are you talking about AppSettings ?
here is a link[^]
"A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder
coolestCoder
|
|
|
|
|
No! actually it is an simple xml file residing under current directory. Somehow it is not opening file and getting the values. I haven't figured out yet what is causing the problem.
Thanks.
What a curious mind needs to discover knowledge is noting else than a pin-hole.
|
|
|
|
|
Is it as simple as the Environment.CurrentDirectory function is not returning what you expect, so the file is not found? I ran your code with an xml file named "app.con" in the same folder as the VS Project, only to have to copy it to the VSProject\bin\Debug folder before the app would find it.
Also, since you don't check any results of your XMLNode fetch, maybe the element or its attributes are not named as you would expect (keeping in mind that XML is case sensitive, though VB isn't)? If your XMLNode object is Nothing, then it doesn't have an Attributes property on which you can call a GetNamedItem method.
My sample "app.con" file has this in it
<root>
<configuration>
<appdefaultvalues>
<add key="huh" value="what">
I pass "huh" to the funtion, and it returns "what". If I pass "Huh", it errors because the XMLNode object is null (Nothing).
Hope this helps.
To err is human. To really foul things up requires a computer.
|
|
|
|
|
Let's try this without masking the xml because it looks like html
app.con =
<?xml version="1.0" encoding="utf-8" ?>
<root>
<configuration>
<AppDefaultValues>
<add key="huh" value="what" />
</AppDefaultValues>
</configuration>
</root>
To err is human. To really foul things up requires a computer.
|
|
|
|
|
Hi All,
Does anybody know how to manipulate with the temporary internet files in .net
I found that there is a file called index.dat. I think this file describes the IE.content in the temporary internet files folder. Is there a way to retrieve the urls from the index.dat (or any other source)?
thanks a lot
Haleem
|
|
|
|
|
DataGridView controler ,
how to change row backcolor at run time?????????????????????
Thiwa
|
|
|
|
|
If you are talking about a GridView in a web project:
Access the RowDataBound event of the grid and
If the e.Row.RowType = DataControlRowType.DataRow Then <br />
e.Row.BackColor = Color.Red<br />
End If
If you talking about a DataGridView in a windows forms project:
If you want to change row colors specifically to alternate row colors, that feature is already built in. Just put something like this in your form load event:
Dim styleDefault As New DataGridViewCellStyle()<br />
styleDefault.BackColor = Color.White<br />
styleDefault.ForeColor = Color.Black<br />
styleDefault.SelectionBackColor = Color.White<br />
styleDefault.SelectionForeColor = Color.Black<br />
dgvMyGrid.DefaultCellStyle = styleDefault<br />
<br />
Dim styleAlternate As New DataGridViewCellStyle()<br />
styleAlternate.BackColor = Color.LightGoldenrodYellow<br />
styleAlternate.ForeColor = Color.Black<br />
styleAlternate.SelectionBackColor = Color.LightGoldenrodYellow<br />
styleAlternate.SelectionForeColor = Color.Black<br />
dgvMyGrid.AlternatingRowsDefaultCellStyle = styleAlternate
If you want to access a specific row and highlight it, just access the style directly: (intMyRowIndex is the row index of the cell you wish to highlight)
Dim styleTemp As New DataGridViewCellStyle<br />
styleTemp.BackColor = Color.Red<br />
styleTemp.ForeColor = Color.Black<br />
styleTemp.SelectionBackColor = Color.Red<br />
styleTemp.SelectionForeColor = Color.Black<br />
<br />
dgvMyGrid.Rows(intMyRowIndex).DefaultCellStyle = styleTemp
Hope this helps.
|
|
|
|
|
TAHNKS.......
I want to change color to specific row.
but my problem is deferent, Im open the Form using another button.
First time I run the program it works, but Im closed the from and open it again it not working????????????????
Why it happened?????????
Thiwa
|
|
|
|
|
Hi,
I want some instructions in converting existing C# Windows Application to C# Web Application..
Please post your replies as soon as possible.
|
|
|
|
|
If the application has been properly architected it should just be a matter of rewriting the presentation (UI) layer - perhaps with the odd addition elsewhere to support a stateless model of working. If it hasn't been well architected then you are looking at rewriting the whole application.
|
|
|
|
|
Spamming different 10 forums with the same question is very rude and totally unnecessary.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
I need to send reports to user in excel sheet format. so plz tell me the way how to convert my data into the excel file format,retrieved from database.
With Thanks & Regards
Amit Sk Sharma
|
|
|
|
|
|
Hello,
My project is about to check the some values in a word document and to open a new word document and type those values and to insert the BUTTON to close that document.
i finished inserting the Button and i dont know how to use that button to close,
I used this code to insert the command button
Selection.InlineShapes.AddOLEControl ClassType:="Forms.CommandButton.1"
Help me to proceed further....
Thanks,
Nanda
|
|
|
|
|
Hello!
I am going to finalize my application what I created with vb.net. However I have faced with an intrique problem about creating and integrating an activation code method. I don't use any database but a XML file to store
DateInstalled and ActivationStatus values in this file as encrypted data because I am not able to overwrite a resource field in my resource file in runtime. Even I use encrypted data in XML file this file can be edited by a user.
Lets assume that one user had installed the app on 3/20/2007 and second user had installed the app. on 3/29/2007. If first user has destroyed the data in XML file, the second user can pass his own XML file to first user with a most recent application installation date. How could you solve such problem? What would be your best approach as method to solve activation integration for your application? Where would you safely store such imported information?
Any advice is appreciated.
Thank You!
What a curious mind needs to discover knowledge is noting else than a pin-hole.
|
|
|
|
|
Because your app is .NET, any code you write to protect it can be decompiled and removed. The big question is, why do you think you need to take it this far ? How many people are going to try to steal your app ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|