Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I'm using VB 2010 and the following console app on my computer:

Module Module1

    Sub Main()

        For Each drive As String In System.Environment.GetLogicalDrives()

            Try

                Dim info As System.IO.DriveInfo = My.Computer.FileSystem.GetDriveInfo(drive)

                Console.WriteLine()
                Console.WriteLine("Name               " & info.Name.ToString)
                Console.WriteLine("VolumeLabel        " & info.VolumeLabel.ToString)
                Console.WriteLine("DriveType          " & info.DriveType.ToString)
                Console.WriteLine("DriveFormat        " & info.DriveFormat.ToString)
                Console.WriteLine("AvailableFreeSpace " & info.AvailableFreeSpace.ToString)
                Console.WriteLine("RootDirectory      " & info.RootDirectory.ToString)
                Console.WriteLine("TotalFreeSpace     " & info.TotalFreeSpace.ToString)
                Console.WriteLine("TotalSize          " & info.TotalSize.ToString)

            Catch e As System.IO.IOException

                Console.WriteLine()
                Console.WriteLine("Drive " & drive & " not available")

            End Try

        Next

    End Sub

End Module

Generates the following:

Name               C:\
VolumeLabel        C-OS
DriveType          Fixed
DriveFormat        NTFS
AvailableFreeSpace 7191638016
RootDirectory      C:\
TotalFreeSpace     7191638016
TotalSize          42443206656

Name               D:\
VolumeLabel        D-DATA
DriveType          Fixed
DriveFormat        NTFS
AvailableFreeSpace 42670780416
RootDirectory      D:\
TotalFreeSpace     42670780416
TotalSize          205294755840

Name               E:\
VolumeLabel        E-DATA
DriveType          Fixed
DriveFormat        NTFS
AvailableFreeSpace 62134550528
RootDirectory      E:\
TotalFreeSpace     62134550528
TotalSize          250056704000

Name               F:\
VolumeLabel        Roxio Creator DE
DriveType          CDRom
DriveFormat        CDFS
AvailableFreeSpace 0
RootDirectory      F:\
TotalFreeSpace     0
TotalSize          146671616

Name               W:\

Drive W:\ not available

Note that I am using slightly different system calls than you are. Try my code on your machine and tell me what you get.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Sure. Take the console app:

Module Module1

    Sub Main()

        Dim password As String = "mypass"
        Console.WriteLine("password=" & password)

        password = Chr(115)
        password &= Chr(101)
        password &= Chr(99)
        password &= Chr(114)
        password &= Chr(101)
        password &= Chr(116)
        Console.WriteLine("password=" & password)

    End Sub

End Module

When you run it you will get the output

password=mypass
password=secret

If you extract the string values from the exe file (I use strings.exe, a tool from the excellent SysInternals Suite available free here) you can see the string "mypass" but not the constructed string "secret".

Please note that if you build "secret" in one line of code like

password = Chr(115) & Chr(101) & Chr(99) & Chr(114) & Chr(101) & Chr(116)

The compiler will optimize this to

password = "secret"

and, therefore, the string will be available for detection. The above method does not prevent someone extracting the string by examining the machine code with a disassembler or a debugger but it does add a level of obfuscation to prevent casual sleuthing.

ryklon commented: Your explanation is good. +1
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Go to the project Properties, then click on "Settings" down the left side. Add as many string variables as you have text boxes to save. For example, if you add the string setting, MyText1 you can load the textbox on form load as

TextBox1.Text = My.Settings.MyText1

and save the value on form close for the next run as

My.Settings.MyText1 = TextBox1.Text

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

If your source code is available to read, I suspect no. String constants in exe files can be easily extracted so if you want to "hide" the password in the exe then you can build it at run time a character or two at a time, even using conversion from numeric values to further obscure the actual password.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

It would really help if you told us what you were missing.

By the way, it is not necessary to have "End Select" in every case clause. Only one of the case clauses will ever be executed.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I tried to recreate your database here and ran the insert. It worked. How do you know the data has not been inserted? Do you have SQL Server Management Studio installed? I should disclose that I prefer ADO.Net over OLEDB. I find that fewer layers between my code and the data means less time debugging.

I see your connection string contains.

AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=True")

I suggest you use

Initial Catalog=Database1;Integrated Security=True;"

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

to add the leading zeroes you can pad the number out by

nextid.ToString("0000")

once you have maxid. You can generate the next id in the select by

select max(ID)+1 as nextid from tblID

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

In what way does it not work? Are you getting an error message? Is the resulting data not what you expect? What are the values of

tbox_username.Text
tbox_password.Text
isAdmin

What is the structure of [login]? I suspect that isAdmin is going into the query as the string "True" or "False". If isAdmin (in the table) is abit value then you will have to translate true/false into 1/0 in the query.

Can't provide definitive help without complete information.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Didn't intend to ding your rep. If you make another post here I'll offset it with a positive vote.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Could someone please undo the negative vote I made on

http://www.daniweb.com/software-development/vbnet/threads/411073

I didn't intend to ding the OP and I can't see any way of undoing it myself.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Is this a sample of code that works or is it a piece of code that you are having a problem with?

If it is the first then you should explain what it does and how. If it is the second then you should explain what you are trying to do and what you are having a problem with.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

If I understand correctly, you could save the positions of the panels in My.Settings then restore those positions when you reopen the app.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

You might want to check out the FileSystemWatcher control. I think it is better to let the system notify you of changes than to continuously poll the system. Wrox Press Visual Basic 2008 Programmer's Reference says:

The FileSystemWatcher class keeps an eye on part of the file system and raises events to let your program know if something changes. For example, you could make a FileSystemWatcher monitor a work directory. When a new file with a .job extension arrives, the watcher could raise an event and your application could process the file.

The FileSystemWatcher class’s constructor takes parameters that tell it which directory to watch and that give it a filter for selecting files to watch. For example, the filter might be “ *.txt ” to watch for changes to text files. The default filter is “ *.* ” , which catches changes to all files that have an extension.

Set the filter to the empty string “ ” to catch changes to all files including those without extensions.

The NotifyFilter property "Determines the types of changes that the watcher reports. This is a combination of values defined by the NotifyFilters enumeration and can include the values Attributes, CreationTime, DirectoryName, FileName, LastAccess, LastWrite, Security, and Size.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Have a look here

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I prefer not to use Math.Round because of one peculiarity.

Math.Round(1.5) = 2.0
Math.Round(2.5) = 2.0

I believe that a rounding function should behave the same whether or not the integer part is even or odd. I was always taught that x.5 always rounds up to the next integer value.

Tangent: I also have a beef with the Random class. Random.Next(minvalue,maxvalue) according to the documentation at msdn.microsoft.com, returns "A 32-bit signed integer greater than or equal to minValue and less than maxValue". Sorry, but "maxvalue" by definition means "the maximum value you want returned". Microsoft should fix this or change the parameter name to maxvalueminusone. You can't just go redefining words as it suits you like Alice's caterpillar.

But I'm not bitter ;)`

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Mine too.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Not a problem. If you know anything about VBA you can still use the logic I laid out to put the code directly into the spreadsheet. Good luck with it.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Why not just use

montera += i & " "

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Because this is the VB.Net forum I assumed you had Visual Studio (for creating VB.Net applications).

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

One suggestion is to declare an array of references to panel and assign the panels to the array in the order you want to reference them.

Private panels(2) as Panel

panels(0) = myPanel1
panels(1) = myPanel2
panels(2) = myPanel3
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Excellent. Much appreciated.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Those are the correct results for rounding those numbers. Consider if you were using decimal numbers instead and rounding to the nearest whole number.

input      rounded
6.312      6.000
6.500      7.000

The easiest way to round is to add half the value you are rounding to, then truncate. If you are rounding (money) to the nearest cent then add half a cent and truncate. If you want to round to the nearest 1000 then add 500 and truncate.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I used a textbox because I hadn't been using VB for that long an it seemed to be an easy control to work with. I didn't feel like doing a lot of research. I just wanted to jump in and have at it. I can see plenty of room for improvement. Probably time for a rewrite.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

You want all numbers (for example) from 6500 to 7499 to give you a result of 7000. If you don't add 500 to the number first then everything from 6500 to 6999 would give you 6000 as a result.

6512 + 500 = 7012    \ 1000 = 7    * 1000 = 7000   correct rounding
6512                 \ 1000 = 6    * 1000 = 6000   incorrect rounding
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

You could try the encrypt/decrypt functions posted by sandeepparekh9 here

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Would it be a big deal to add an option to the Search to restrict results to the current forum only? When I am on the VB.net forum, for example, and I do a search, I am interested in results in the VB.Net forum only.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Go ahead and post the code. It would also help to see the structure of the table. How you set the value of a local boolean for isAdmin will depend on the field type. For example, if isAdmin is a single character field containing "Y" or "N" (and assuming you are using ADO) it would look something like

rset.Open("select isAdmin from mytable where username = '" & username & "'",...

dim admin as Boolean = False

if not rset.EOF then
    admin = rset("isAdmin").Value = "Y"
end if

rset.Close()
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Try

1000*((6511+500)\1000)

With a little playing around you should be able to roll your own Round function to round to an arbitrary digit.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I've attached a project and an Excel spreadsheet. You'll have to modify the code to point to wherever you put the spreadsheet. I hope this helps.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I'll try to post something for you in the morning. With luck, you can tweek it to what you need.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

If you are unable to write it yourself are you going to be able to support it?

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I use the DivX converter program and VirtualDub(Mod) under Windows 7

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

To Dan:

The OP merely asked how computer shops install or reinstall Windows (of various flavours). It seems to me that by offering more than just the latest and greatest version of an OS (Windows/Linux/whatever) they WILL attract customers. In my former life (pre-retirement) I was frequently called upon to support applications that would not run on the "latest and greatest". Believe it or not, in 2008 I was still providing support on a custom app that would not run on anything newer than Windows 98. I, myself, have a piece of hardware (Plextor TV tuner) that will run only under Windows XP. As such, I plan to keep my old IBM ThinkPad (XP Pro) running for as long as I possibly can.

That doesn't prevent me from moving along with the tide into the era of Windows 7. That also does not mean that users who choose, for whatever reason, to remain with Windows XP should be left high and dry. Any computer shop that followed your reasoning would, in my opinion, LOSE customers. The way to attract customers, especially in this economy is to provide BETTER service than your competitors.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I start with an array of multiline textbox controls (see attached). It is dimensioned as

Dim Square(2, 2, 2, 2) As System.Windows.Forms.TextBox

It is set up as a 3x3 grid where each unit in the grid is another 3x3 grid.

Each control is sized so that when set to the string "1 2 3 4 5 6 7 8 9", the digits appear over three lines. The dimensions are arranged so that when you vary the last two coordinates (k and l of i,j,k,l) you can access one set of 9 (3x3) cells. By choosing which coordinates to vary you can scan any one 3x3 cell, any row or any column.

In order to eliminate possibilities, every time I enter a single didit in a cell, I rescan and recalculate all remaining cells. If, during a scan a cell is reduced to a single possibility (ie that cell is solved), I rescan the entire grid.

That was my approach anyway. I'm certainly open to other suggestions.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

What do you need help with? At the highest level you have

retrieve user info from database
display on form

How much detail do you need? What have you done so far? Is your problem defining the database, populating the database, retrieving from the database, writing to another form? What is your level of expertise?

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Like you, I prefer to solve by logic rather than by brute force. I don't, however, enjoy the drudgery of determining what digits are possible in blank squares. My solver allows you to enter the known digits and displays the remaining possible digits in the other cells (solved cells in large font, unsolved cells in small font). Each time I solve a new cell it recalculates the remaining cells. All of the fun and none of the tedium.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Try

MyExcel.Workbooks(1).SaveAs(filename)

or

MyExcel.ActiveWorkBook.SaveAs(filename)

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

textbox.Text = (timer1.Elapsed + timer2.Elapsed).ToString

thedonedeal commented: This one works. +2
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I can't comment on that code because I don't speak VBA. What is your level of programming expertise? Is it sufficient so that you can turn

On Sheet1
 
start at row 1
 
while first cell in this row is not blank
 
    get name from first cell
 
    for each column from 2 to 500
        get month (m) and day (d) number from date in this cell
        copy name to first blank cell in column d of sheet m+1
 
    get next row

into actual code?

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

If blank cells are to be ignored then why iniclude them? In any case, you can scan the row from column 2 to column 500 and just process those that are non-blank.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I wrote something like that quite a while back and I used an 3x3x3x3 array of textboxes. By picking various combinations of indexes I was able to check for duplicates in any of the required directions.

If you are interested, there is a very good book by Wei-Meng Lee (Apress books) titled Programming Sudoku. It covers both generating and solving algorithms.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

And, lest I forget, congratulations on getting it working. Now make it better.

Never stop learning. What you learn today will make it easier tomorrow.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

You didn't ask a question so I'm assuming you posted the code for comments. I have a couple of comments and a suggestion.

You should add whitespace to make the code more readable. Codethathasnowhitespaceismuchhardertoreadsopleaseuseit.

Your code has no comments. All programs should have a header with comments that give (minimally) the program name, a description of what the program does, and any components (non-standard) required to build/run the program. I like to include an audit trail that shows when the program was written and when modifications were done. My personal preference is to create the header as a string variable which I can use in the "about" box. Each sub/function should also have a short header describing what it does. Variables, especially those declared at the class level, should have a comment explaining their function. You may know what everything is now, but you might not in 6 months. And it's easier if someone else has to look at your code (and it also improves their opinion of you as a programmer).

Now the suggestion.

You have a separate button.Click handler for each of the digits. You can simplify that by having one handler that handles all ten digits.

Private Sub DigitClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button0.Click,Button1.Click etc
    RichTextBox1.Text = RichTextBox1.Text + sender.Text
    curval = Val(RichTextBox1.Text)
    pre_curval = Val(RichTextBox1.Text)
End Sub

Just replace "etc" with the remaining buttons. You could use the same technique to group the handlers for the math …

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I don't follow. On Sheet1, what is the correlation between the column and the day? For example, for Jane you have 12-Jan in column B and 14-Jan in column H. There is only one day between 12 and 13 but five blank columns.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Welcome. Don't forget to mark this thread as solved.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

First a little code, then a few comments. To get at the workbook you have to create the Excel object.

Dim xls As New Excel.Application
Dim sheet1 As Excel.Worksheet

xls.Workbooks.Open("d:\temp\test.xls")
sheet1 = xls.Workbooks(1).Sheets(1)

This creates the Excel object and opens an existing Excel workbook. The assignment to the variable, sheet1, is not really necessary but it saves a lot of typing. Now you can access the cells by row and column number using the "Cells" collection. The top, left cell is

sheet1.Cells(1,1)

and you can get/set the value by the "Value" property as in

dim name as String = sheet1.Cells(1,1).Value

To access cells on another sheet you use

xls.Workbooks(1).Sheets(sheetnum).Cells(row,col)

or

With xls.Workbooks(1).Sheets(sheetnum)
    .Cells(row,col).Value...
End With

Having said that, you may have a problem. On sheet1, you have blank cells mixed with non-blank cells so there is no obvious way (because rows are indefinitely long) of determining when you have processed all the dates in a given row. I don't see any obvious reason for having embedded blank fields.

Once you have finished crunching the numbers you have to clean up. That consists of saving the workbook, closing the Excel application and releasing all objects. If you don't release the objects then you may end up with multiple copies of Excel running in the background chewing up resources. To check this just run Task Manager and look for Excel.exe. This didn't used to be necessary (at least not from vbScript). I don't …

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Is this the algorithm?

Sheet2 = month 1
Sheet3 = month 2
etc

On Sheet1

    start at row 1
    
    while first cell in this row is not blank
    
    	get name from first cell
        start at column 2
        
        while this cell is not blank
            get month (m) and day (d) number from date in this cell
            copy name to first blank cell in column d of sheet m+1
            get next cell
            
        get next row

I'll point out that this is the VB.net forum and what you asked for is a VBA solution. If you code it as VBA then the code would appear in every workbook (I presume you would have one for each year). That means one copy of the code for every year for everyone who uses their own copy of the workbook. You CAN code it as a VB app in which case the app would load the Excel workbook, crunch the numbers, then save it back out. I can show you how to do that if you prefer.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Removed. I had a comment but Jx Man beat me to it;)

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

You can replace a single quote with two single quotes before you add the string to the query. For example

insert into table1 (name) values('D''Costa')

If you need to search for fields that contain characters like '%' and '_' you can use the ESCAPE keyword as follows:

select * from table1 where name like '%\_%' ESCAPE '\'

This will return all names containing an underscore. We have defined the backslash as a special character to prevent the underscore in the LIKE clause from being used as a wildcard.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

You didn't attach anything that I can see. Can you please explain the problem a little more clearly?

search dates on Sheet1 and copy the name associated with that name

Are the dates in specific rows and/or columns? What do you mean by "name associated with that name? If you can describe the problem step by step as if you were doing it by hand then the solution (the code) often becomes much clearer.