|
thanks for the reply
But I guess it will take some time to run the application.By that time user can do anything(eg: opening MyComputer) on the system. Which I want to avoid for security reason.
Is there any method for the same.
Thanks in advance
-----------------------------
I am a beginner
|
|
|
|
|
Try making a windows service instead of a windows application.
|
|
|
|
|
0) Do not cross post please (you posted in 3 forums)
1)
himangshuS wrote: All I need is to stop the user to do anything in the system(before my application Run).
Bad, very bad, your application should never prevent users from working on there pc.
himangshuS wrote: Later he should be able to exit the application and do other staff(like opening the explorer etc)
Beter
As to how to do this, I'm afraid you can't. the only thing you can try is to have a boot screen in your application that is topmost and fullscreen.
|
|
|
|
|
Hello all. I am trying to write a simple program that defines a Car class and writes an XML Serialized Car object to an XML file. This is a Console app. Right now, I have the XMLSerializer Object defined and initialized with Module Scope. Within the main method, I create a filestream and a streamwriter that I pass to it to write the serialized Car object to the file. This works fine, but when I re-open the program after closing it, it cannot read the object back in once more than one have been written to the .xml file. I assume that this is because when a second object is written to the file, the xml header is re-inserted into the same file, and it is throwing the reader off. I have posted me code below.
I am trying to learn how to read and write XML with VB. Any help would be appreciated.
Imports System.Xml.Serialization
Imports System.IO
Public Module Module1
Public xs As New Xml.Serialization.XmlSerializer(GetType(Car))
Dim car1 As Car
Dim car2 As Car
<Serializable> Public Class Car
Public Make As String
Public Model As String
Public Color As String
Private year As Integer
Public Property TheYear() As Integer
Get
Return year
End Get
Set(ByVal value As Integer)
year = value
End Set
End Property
Public Sub New()
Make = "Chevy"
Model = "Camero"
Color = "Tan"
year = 2003
End Sub
End Class
Public Sub Main()
Try
Dim fileName As String = "C:\\XMLCar.xml"
Dim f As New FileStream(fileName, FileMode.Append, FileAccess.Write)
Dim t As StreamWriter = New StreamWriter(f)
car1 = New Car()
xs.Serialize(t, car1)
t.Close()
Dim sr As New StreamReader(fileName)
car2 = xs.Deserialize(sr)
Console.WriteLine(car2.Model)
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
Console.ReadKey()
End Sub
End Module
"If you don't know where you're going, you'll probably end up somewhere else." Yogi Berra
|
|
|
|
|
change the filemode to 'create'
Dim f As New FileStream(fileName, FileMode.Create, FileAccess.Write)
or add this line before craete the file stream
If IO.File.Exists(fileName) Then IO.File.Delete(fileName)
'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous
'Life's real failure is when you do not realize how close you were to success when you gave up.' ~ anonymous
|
|
|
|
|
That would work if I were trying to only store data from one running of the app. However, I am really trying to be able to make the XML file grow through each subsequent running of the app. I could perhaps use your idea of deleting the file each time, if I could figure out how to get each object in the file into a collection on form_load so that they could be written back to the file when the app is closing.
I am having a hard time getting my code to work with multiple objects. Is there a way to do this? Thanks.
Btw, the code from my original posting is not complete.
"If you don't know where you're going, you'll probably end up somewhere else." Yogi Berra
|
|
|
|
|
forgive...my misunderstanding.
in order to do what you want, upon every save of the serializer...add a delimiting row (like a row of asterisks). then your read part would read until it finds the delimiting row and then deserialize that chunk. read the next chunk and deserialize that...etc.
<?xml version="1.0" encoding="utf-8"?>
<Car xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Make>Chevy</Make>
<Model>Camero</Model>
<Color>Tan</Color>
<TheYear>2003</TheYear>
</Car>
***************************************************************
<?xml version="1.0" encoding="utf-8"?>
<Car xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Make>Chevy</Make>
<Model>Camero</Model>
<Color>Tan</Color>
<TheYear>2003</TheYear>
</Car>
'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous
'Life's real failure is when you do not realize how close you were to success when you gave up.' ~ anonymous
|
|
|
|
|
I have a field of Image path on database and I need to display the image of student in crystal report. I am using VS2005 with crystal report version 9. I have added the unbound column named "Image" of type system.byte in Data Set and at the load event, I have write the following code.
Dim da As New DataSet1TableAdapters.AdmissionFormTableAdapter
Dim dt As New DataSet1.AdmissionFormDataTable
da.FillByStudentID(dt, _studentID)
Dim dtCopy As New DataTable
'''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Code Start to Set Image
'''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim blankFile As String = "C:\Program Files\blank.JPG"
If dt.Rows(0).Item("ImagePath").ToString <> "" Then
Dim s As String = dt.Rows(0).Item("ImagePath").ToString
If FileIO.FileSystem.FileExists(s) Then
Dim fs As FileStream = New FileStream(s, FileMode.Open, FileAccess.Read)
Dim image(fs.Length) As Byte
fs.Read(image, 0, Convert.ToInt32(fs.Length))
dt.Rows(0).Item("Image") = image
fs.Close()
Else
Dim fs As FileStream = New FileStream(blankFile, FileMode.Open, FileAccess.Read)
Dim image(fs.Length) As Byte
fs.Read(image, 0, Convert.ToInt32(fs.Length))
dt.Rows(0).Item("Image") = image
fs.Close()
End If
Else
Dim fs As FileStream = New FileStream(blankFile, FileMode.Open, FileAccess.Read)
Dim image(fs.Length) As Byte
fs.Read(image, 0, Convert.ToInt32(fs.Length))
dt.Rows(0).Item("Image") = image
fs.Close()
End If
'''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Code End to Set Image
'''''''''''''''''''''''''''''''''''''''''''''''''''''''
dtCopy = dt.Copy
Me.rptAdmissionForm1.SetDataSource(dtCopy)
Me.rptAdmissionForm1.SetParameterValue("ID", _studentID)
When I run the code, error comes that "unable to cast type of system.byte to system.IConvertible",
although the datatype of column "Image" is system.byte, and when I debug the code, it shows the datatype of dt.Rows(0).Item("Image") = System.DBNull, Please help me out..!
|
|
|
|
|
For x = 0 To y
RandomNumber = RandomClass.Next(i)
Next x
is the Code I'm using what I'm wondering is there a way to check and make sure the same random number doesn't get picked twice?
|
|
|
|
|
The principle is that you would need to store each number you generate, and check each new random number against that store. Could get very expensive if you are generating a large number of random numbers.
|
|
|
|
|
I understand to use it as an array and check it against each other however I don't know the code you would use to check
RandomNumber(r) where r were to equal 9 against 0-8 if you could help me with that I'd greatly appreciate it.
|
|
|
|
|
GregoryWB wrote: is there a way to check and make sure the same random number doesn't get picked twice?
That is not the purpose of a random number generator: it should generate numbers that are independent of previous numbers, hence doubles are perfectly normal.
If you need all different numbers, randomly picked from a limited set, then that is what you should do: construct a set, pick one element from it randomly and remove it, then repeat until you have enough (or the set got empty).
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
well I'm trying to create a Raffle program with Name(x) and it has more then 1 winner, I'm fairly new to programming so not sure how to remove 1 Element each time it is selected, any pointing to document that would explain this or help would be great.
|
|
|
|
|
GregoryWB wrote: not sure how to remove 1 Element
Well, use a real collection such as a List<int> and fill it with all N relevant numbers.
Run your random generator for the range [0, N-1] and use that number as an index into the List, copy that number AND remove it from the list (which now has one fewer element, so adjust your random.Next call next time you call it).
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
That the OP was building a raffle number program would have been fairly pertinent information, don't you think?
In that case I would have recommended the same approach you did!!
|
|
|
|
|
Private Function rnd_between_limits() As Integer
Return (Int(( Initial_limit+final limit-1 ) * Rnd(Now.Millisecond + Now.Minute + Now.Second)) + Initial_limit )
End Function
use this if ya want to generate a rnd number between certain limits
TheMrProgrammer
|
|
|
|
|
Hi all,
I am trying to write a simple application that will read data from a SQL database and allow the user to make changes and then update the database.
I am using VB 2008 Express on a XP machine and SQL Server 2005.
The program will be run on different servers with static ip addresses.
The program will consist of two user forms:
1. Login form (User name and password is stored in a table in the database)
2. Main Form (A Customer Masterfile table in the database)
I have done a bit of coding in VBA, but would like to do this in VB 2008 so that I can generate a standalone app that can be run without excel.
My idea is to do it bit by bit and learn as I go along, but I want to start the right way so that I do not have to redo everything at a later stage.
My logic is as follow:
Create Login form with Username, Password, Ok button, Cancel Button, Server Info.
(the username and password will be verified against the values in the database)
The IP, Databasename, Sql Login and Sql password must be entered and remembered next time the program is run. In VBA I would store this info in a Excel sheet, but were can I store this when using VB2008?
If the login is ok it will load the Main form otherwise you need to retry the password.
The Main form will get information from a customer masterfile that will be loaded in text boxes that can be edited and once complete it can be uploaded to the database.
For a start I would like to do the userform and server connection.
Any help would be appreciated.
Thanks.
|
|
|
|
|
Seems like reasonable logic...
For simplicity, instead of prompting the user for the IP, Database Name, SQL Login etc, why not store these either in the app.config file, or in a global constant within your system.
If at a later time you want the user to enter these during setup, or whatever, you can update your system to handle that...
Hint for login form - use a couple of text boxes for username and password. Open a connection to the database (see www.connectionstrings.com for help) and get a datareader for the record containing the specified username. If the datareader is empty, the user does not exist. If the datareader is not empty, compare the passwords and let in/deny access depending on how it goes.
|
|
|
|
|
Thank you for the reply Damian.
I found a article on Code Project on creating an app.config file and this seems to be the easiest way for a start. Like you said I could always expand on that at a later stage. ( would I then edit the app.config file through code, or is this done in another way?)
I will attempt to get login form going following your advice.
Thanks again!
|
|
|
|
|
There are several different ways of updating an app.config file - certainly through code is one way.
Good luck with the login form!
|
|
|
|
|
Follow Damiens advice and think about the SQL login types.
Active Directories - this uses the AD user groups and a connection is created using the users credentails
App Connection - this is where the application has a standard SQL logon and uses that to get the data (you need this to get the logon information anyway).
We use the latter but we use internal authorisation to manage the internals of the apps.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
hello
i am developing an application where i generate my report in excel
and have to save in some folder in c drive i wrote my code like
Dim xl As New Excel.Application
xl = CreateObject("Excel.Application")
Workbooks.Add()
xl.Visible = True
xl.Columns("A").columnwidth = 5
xl.Columns("C").columnwidth = 25
xl.Columns("B").columnwidth = 25
With xl.Range("A" & ii, "C" & ii)
.Interior.ColorIndex = 5
End With
'please suggest also how to change forecolor of cell from "A" to "C"'
i get my data from data base and load it in excel and it is working but now i want to save this file in some folder for that i wrote code like
If Not IO.Directory.Exists("C:\Backup") Then
IO.Directory.CreateDirectory("C:\Backup")
End If
xl.SaveWorkspace(" C:\Backup ")
but this code is not working
so,please suggest what shall i do to save it in this directory...
|
|
|
|
|
nazimghori wrote: but this code is not working
So what errors are you getting? Any exceptions? Do you have rights to save there? What OS are you running on, and under what type of user account?
|
|
|
|
|
nazimghori wrote: please suggest also how to change forecolor of cell from "A" to "C"'
Try using:
range.interior.color =
|
|
|
|
|
Well, the save fails because you haven't provided a file name. You gave it the anme of a folder, but no filename...
|
|
|
|