|
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...
|
|
|
|
|
Hi all,
Can somebody help me/point me on how to register an exe as a service. I googled for it but it lead to confusion more than any help.
My exe would require a command line argument to start. So I can put it in a batch file and would like to register the batch file as a service.
Thanks
--Raghu
|
|
|
|
|
I seriously do not recommend doing this, but you can use SrvAny[^] to run an .EXE as a service.
|
|
|
|
|
Ditto. What is so hard about using InstallUtil? If you need an installer, use this KBA: http://support.microsoft.com/kb/816169
Any suggestions, ideas, or 'constructive criticism' are always welcome.
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
|
|
|
|
|
Hi
Let me explain.
I have an application built on VC++ 2005 (myApp.exe). I want to install it as a windows service. My application requires a an argument to start. How I do that.
As I am new to this, I created a service with notepad.exe as the executable, but when I try to start it, this is what I got
Error 1053: The service did not respond to the start or control request in a timely fashion
I have the .net 2.0 framework installed.
Only straight answers please. The one like ..
>>Ditto. What is so hard about using InstallUtil? If you need an installer, use this KBA:
by Jon_Boy is of no help, unless you are half bald ( or may be completely bald, you need to get bald to get the solution from Jon_Boy)
Thanks
--Raghu
modified on Wednesday, May 27, 2009 6:43 AM
|
|
|
|
|
Raghuveer D wrote: unless you are half bald ( or may be completely bald, you need to get bald to get the solution from Jon_Boy)
And that means what?? Bald people don't know what they're doing??
You're getting the error message because the ServiceManager is expecting a response to a Start command that it is not getting back. Why? Because your code is not written as a "pure service".
Rewrite your application as a service and you won't have any of these problems. That is, if your not half-bald and really know how to write a proper service app...
|
|
|
|
|
Sorry, I showed my frustration there. Anyways, people who know lot of things, seen lot of things get bald( not necessarily though). I always had that belief that bald guys have more information in their brains. Correct me if I am wrong.
|
|
|
|
|
|
Raghuveer D wrote: srvany helps, but it do not result is a pure service.
Of course it doesn't! If the code is not written AS A SERVICE application, then it's NEVER going to be a "pure service", even if you use WinServ.
|
|
|
|
|
Yes, Dave, thanks for you reply.
I have a question here. Is it lot of pain to convert my application to be re-written as a service.
Thanks
|
|
|
|
|
|
Hi All,
I am using vb.net 3.5 and Sql Server 2005
There is no problem with connection if Server Name and Database Name Exist.
But the Error occurs when Try to connect the server which is not available. then my application goes hang. It is continue Searching.
I'm using :
Public Sub ConnectConfig(ByVal DSource As String, Optional ByVal Uid As String = "", _
Optional ByVal Pwd As String = "", _
Optional ByVal InCat As String = "", _
Optional ByVal AuthType As String = "")
Dim ConnString As String = ""
If FrmConfigSetup.cbAuth.SelectedIndex = 0 Then
ConnString = "Data Source=" & DSource & ";Initial Catalog=" & InCat & ";Integrated Security=True;Timeout=60;" & ""
Else
ConnString = "Data Source=" & DSource & ";Initial Catalog=" & InCat & ";Uid=" & Uid & ";Pwd=" & Pwd & ";Timeout=60;"
End If
SQLConn = New SqlClient.SqlConnection(ConnString)
If SQLConn.State = ConnectionState.Open Then
SQLConn.Close()
SQLConn.Open()
Else
SQLConn.Open()
End If
End Sub
when it'sTrying to open the connection then goes hang.
So, What can I do , please help me.
Arindam Banerjee
Sr. Software Developer
Rance Computer Pvt Ltd.
Kolkata (India)
|
|
|
|
|
The timeout in the connection string is used for responses to command queries. It does not apply to the connection itself. Your connection attempt can take a few minutes to timeout and throw an exception.
pdnet wrote: If SQLConn.State = ConnectionState.Open Then
SQLConn.Close()
SQLConn.Open()
Else
SQLConn.Open()
End If
What the heck is this?? Since you're creating a new connection object all the time, you just need to Open it. A new connection object's state is always going to be Closed.
|
|
|
|
|
Why don't you ping that server to make sure it is exist before connecting to it?
Like car accidents, most hardware problems are due to driver error.
Samir R. Ibrahim
|
|
|
|