How to Open VB.NET Form in Design Mode - vb.net

I have a VB.NET solution created in Visual Studio 2017. It seems like I used to double click Form1.vb in the Solution Explorer to open the form in design mode so I could add buttons and such.
Now no matter what I do, I can't open the design form window. It seems like there are fewer elements in the Solution Explorer, but I'm not sure:
Can someone tell me how to open the Form Designer again? Thanks.

The issue is exactly as I described in the first comment. Only the first type in a code file can be designed. If ServerForm is declared after ClientClass then ServerForm is not the first type in the code file, thus it cannot be designed. You could move ClientClass after ServerForm and that would address the issue but I would suggest doing what you should have done in the first place and declaring ClientClass in its own code file.
To that end, select the entire ClientClass definition and cut it to the Clipboard. Right-click your project in the Solution Explore and select Add > New Class and name it ClientClass, then select all the code in the new file and paste what you previously cut. You should then be able to build your project and now open your form in the designer.
I have two further suggestions. As I said, you appear to have renamed your form in the code. Don't do that. You now have the class name and file name out of sync. If you want to rename a type then you should also rename the file it is declared in. As you should almost always have just one type per file, they should be named the same. If you right-click the item in the Solution Explorer and select Rename, you can rename the file and you will then be prompted to similarly rename the type, which you should accept.
Finally, you should pretty much NEVER use "Class" as a suffix on the name of a class. You'll note that the String type is not named StringClass. You really ought to rename your ClientClass type Client. You might want to elaborate on what type of client, but the "Class" suffix is not a good idea.

Related

VB in Visual Studio Adding a class module will it have access for the form.vb I've built?

Hello thanks for reading my question, I've build a user form with controls to control equipment via RS232 and USB. I've also added a separate class module "class.vb" to hold miscellaneous functions like writing to an ini file.
When I'm in the code section of the Form.vb and I type txb for text boxes that I have in the form visual studio pops up a nice list of all things in the form that start with txb.
However, when I do the same thing in my class.vb it does not do this and even if I type the whole thing such as txbModulation and then add the dot after it does not come up with the list of properties.
Does the class.vb have access to Form1.vb controls?
When I'm in the code section of the Form.vb and I type txb for text
boxes that I have in the form visual studio pops up a nice list of all
things in the form that start with txb.
This is because when you start typing a variable name, Visual Studio starts looking for a match. It looks in block scope first (a for or while loop maybe), then at local (function/sub) scope, and finally at class level (a form is a class). It will also look for any matches in Modules if you have them. See Scope in Visual Basic for more info.
Since the Form and your INI Class are different, they cannot see each other unless you pass references or somehow pass values via parameters to subs/functions.

Create empty file using two textboxes

I'm creating a simple program that will allow the user to with the click of buttons to create empty files, delete files, rename them and much more. Now to my question. When I click on the Create New File button (obviously empty), I have a new window pop up.
In that window I want two textboxes and one button to be present. The first textbox shows the initial path to the file I want to create (i.e C:\Users\Username\Desktop\) and the second textbox will show the name plus extension of the file (i.e Hero.dll).
The button will then combine these and make the file and put it in the directory the textbox is displaying. However, I'm having trouble with the textbox displaying the name.
Also, the textbox displaying the path is called txtPath and the textbox displaying the name is called txtName.
So this
IO.File.Create(txtPath.Text, txtName.Text)
gives me this error
Conversion from string "Hero.dll" to type 'Integer' is not valid.
and I noticed in the code (Intellisense I'm assuming is what it's showing in) it says
Functions File.Create(path As String, bufferSize as String) As Filestream
and so bufferSize is the txtName textbox by then.
How would one go about fixing this so txtName does what it's supposed to do, or do I simply have to roll with only displaying the path?
I have tried a couple of things myself but none worked the way I wanted it to.
Also, creation of the file works like a charm if the code only says
IO.File.Create(txtPath.Text)
given the name of the file is also displayed in the path.
I'm open for any kind of help, as I've tried several different "solutions" I've come up with myself. Thank you!
The first parameter should specify both the path and the file name. You can, and should always, use Path.Combine() to concatenate paths and file names.
Also, the File.Create() method opens a FileStream to the file, which keeps it locked until you close it or the application. If you do not intend to use this FileStream to write data to the file you ought to dispose it so the file lock is released.
IO.File.Create(Path.Combine(txtPath.Text, txtName.Text)).Dispose()

Can't change code copied from form in different database

Building a Maintenance log book in access. Had to redo a data entry form so I started over with a new form in a new database then copied some working code from the old form to the new. In doing so I changed the names of a couple of combo boxes in the new form in order to keep things consistent. Problem is, the code I copied has the old name of some of the combo boxes and I can't change those names to the new names. The new names don't present when using autofill, just the old ones. Is there a way to correct that.(Easy, I Hope)
Example: in the old form the name of a combo box was actionCB. In the new form the box is named ActionCB, but now any code I write uses the old name.
This might be happening because you have compilation errors. Try compiling the application and fixing any errors. Or possibly this could happen if you happened to be stepping through the code at the same time (but I doubt it from your description)? Also VBA is beautiful in the fact that almost always you can make code changes while stepping through the code... but I've experienced the changes not saving from time to time.
MODIFIED FOR NEW QUESTION
As to your second question below in the comments. You can view and select a Form or Reports controls by using the Forms Property Sheet. If you look at the combobox at the very top of the property sheet it lists all Form or Report controls. You can select these objects by simply selecting them from the combobox.
Access is not case sensitive
"Example: in the old form the name of a combo box was actionCB. In the
new form the box is named ActionCB, but now any code I write uses the
old name."
If you're code is not updating to reflect the "ActionCB" name automatically, then you're probably trying to reference it where it's not available. This isn't going to generate an error if you don't have Option Explicit statement at the top of your module.
It'll just assume you know what you're doing and assign it to a Variant data type.
Put Option Explicit at the top of all your modules, and the debug | compile untill all errors are fixed.

Copy A form to use in the same project

I need to have 8 forms of the same format within the same project
I dont really want to specifically place all the buttons etc in each of them
Is there a way i could copy and paste the format and then change all the button names etc?
The program is a flight booking system so for different flights on the same plane type i need multiple forms
To duplicate a Windows Form, you have to do these simple steps :
1- Open the folder project in File Explorer.
2- Copy the three files, .vb, .Designer.vb, .resx of the form that you want to copy.
3- Rename the files with the name you want.
4- Open the file with a text editor for example Notepad++.
5- Modify the Class name in the .vb and .Designer.vb file.
6- Include those files in the project.
Below an example demo :
Ok you can do copy past from your form1 ,a form CopyOfForm1 shoud be created .
you change name "form2" instead of "CopyOfForm1"
Change name of class "form2" instead of "CopyOfForm1"
In CopyOfForm13Desiner.vb you must also change name of class "form2" instead of "CopyOfForm1"
Have a look at this Gif picture :

Open a VFP Database Container with OpenData event coded

I am migrating data from a Visual FoxPro Data Base Container to Excel using VBA.
After trying and failing various settings of the Connection String in order to open the Container, I discovered that at Container was placed code at OpenData event; this code asks a password to open the Container. This prevents other programs open the Container for access to data, including the Password parameter of the Connection String.
Are there a way to open the Data Base Container with OpenData coded event? If the answer can be implemented in VBA, please let me know how I can do it.
Thanks for your attention.
PD: Forgive my english. Is not so good.
Solution details would probably depend on what the (custom) "Stored Procedure" code in the Vfp database is doing exactly, where one way could be simply removing it. If you got a Visual FoxPro IDE, you could for example do so by using the IDE's "Command Window":
MODIFY DATABASE ?
and then right-click the Database Designer window, choose the desired "Event" in the Properties dialog -> "Edit Code".
If then for example the code would simplified look like
PROCEDURE dbc_BeforeOpenTable(cTableName)
*Just before a table or view is opened. Return .F. to prevent table or view being opened.
RETURN INPUTBOX("Password") == "Test"
ENDPROC
... you could simply
RETURN .T.
instead