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()
Related
I split a database and created a search form in the front end. It works there, but when I copy the front end, the search form doesn't work there
The form is a continuous form and has my table as a datasource. There are a number of bound fields in the detail section and a number of unbound fields in the form header. On the click of the search button, I use vba to build a sql select string and use Me.RecordSource = strSQL. Again this works in my original front end db. After realizing it doesn't work in a copy, I have tried copying and pasting the form from one front end to another, export/import, recreating it, hard coding a select, trying to display a message box on the click...nothing seems to work on the button click (tried double click too). If I build a button with the wizard, it will work, but they are using built in macros.
Any thoughts? Thank you in advance.
If no code seems to run in your new database (including MsgBox), then it is quite likely that the new database is in a folder that Access doesn't recognize as "trustworthy" and has therefore turned off code running.
Check that the folder where the database is currently located is allowed to run code, and if not add the folder:
File|Options|Trust Center|Trust Center Settings|Trusted Locations
Regards,
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.
Trying to get the name of the active window with it's description, can't find any method.
My problem is that while I can access document's file name with Document.Name, I can't get the commentaries that Word attaches to it, like (Compatibility Mode, Last modified by User etc), without them, the method Windows(Document.Name) doesn't work, is there any solution for this?
My program opens four new documents and switches in a loop the active document, taking information from the original and putting some excerpts in the new ones.
Everything works when there is no commentaries for documents, but as they appear, program breaks, saying:
5941 The requested member of the collection does not exist
Thanks for reading!
This:
Windows(1).Document
will give you the document associated with a window. (You may need to loop through the windows to find the one you're interested in.)
Once you have the document you can access its properties:
Windows(1).Document.CompatibilityMode
Hope that helps
I am wanting to add a logo to all my forms/reports etc. I want to either store the image once in the database, even in the front end is okay, or I want to access a picture on the network/local computer. I really don't care. I can store a location in a table, and use a dlookup call as the control source in a picture control, and it works, but there is a noticeable delay from when the form opens and when the picture actually appears. If I paste the picture in to every place, it works great! But if I want to change the logo, I must open all my forms/reports and change every single one.... there has to be a faster way to change out my logo pictures and still get them to load instantaneously. Can you help?
You could use vba perhaps. Create a global variable in a module to link to a file location. You could then use an image control on each form and set the source to the file location stored in your variable on the open event.. That way you would only ever change the value of the global.
Your code might look like this in each form:-
Private Sub Form_Open(Cancel As Integer)
Image0.Picture = yourGlobalFileLocationVariable
End Sub
I have a winform project which lists all the files in a specified folder. It allows the user to select a new destination for each file, and when the user has chosen the destinations for all files that he would like to be moved, it moves the files, one by one.
My next step is, I need to display a confirm form when the files are being moved, and add each file's name and destination to the confirm form as it is being moved.
My question is:
How can I add more text to the confirm form's controls after I already loaded it (using confirm.showdialog() from my other form, without any user interaction? I imagine that I need to do it from the original form, because it needs to display each one when it starts to move that file, but I'm open to any suggestions:)
TIA
Both above answers are good.
If I understand correctly, your main form will allow one to select multiple files, then select their destination and launch the move process. If that's what you need, I would simply do the following:
Create a new form that would report the process to the user, without requiring any interaction, but just to inform the user what file is being moved;
Create an instance of a BackgroundWorker object, and call the file-move method from the BackgroundWorker.DoWork() method (within your main form);
Flag your BackgroundWorker to report progress, then call the BackgroundWorker.ReportProgress() event handler from within your move-file method;
Use the previously created list of file names to get its name and report it to your file-move dialog form while the file is being changed. A simple DataBinding over a Label should do the trick while you'll move your CurrencyManager to the next item within the list, or you could simpler use the list indexer to get the filename at a particular index;
When the user launches the move process, get your filenames and and count them, then set your ProgressBar Maximum value to the number of files you have.
The BackgroundWorker.ReportProgress() method takes an integer value as its argument, then, with your ProgressChanged() event handler, you will be able to display the name of the file being copied to your window by getting the filename at the index location, index given by your ReportProgress() method.
This will allow you to use the performance of a supplemental thread, without "freezing" your main thread from which your form has been created, then you will be able to simultaneously perform your file move, and display the filename to the progress-form, while illustrating to your user visually what the progress is about through your ProgressBar control, and displaying the filename as required.
Does this help?
Wouldn't it be simpler to make another form instead of using preset dialogs?
that way you can just have a textbox that you populate and refresh
You could do put all of the code to show the moving of the files inside the confirm dialog window.
But to give a more complete solution could you tell me how you are gathering the file moving information.
A Good solution would be to just pass in the list of the files to be moved and then perform the moving function in the dialog.