Jump to content
Xtreme .Net Talk

3xodus

Avatar/Signature
  • Posts

    47
  • Joined

  • Last visited

Everything posted by 3xodus

  1. Will setting the label's AutoSize property to True do what you want?
  2. Hi, C# does have a DoEvents - try: Application.DoEvents(); Personally if I am using a routine which may take a while and there is a progress meter, I like to always launch the routine in a seperate thread. I hope this helps, I'm new to C# myself so my appologies if I'm wrong about DoEvents (I don't have VS installed on this PC)
  3. Thanks for the reply coldfusion244 - the information on scope deliminators is very useful :) I've just worked out why my code above wasn't working and it turns out it wasn't a problem with the if statements, however I still need to learn how to use them properly. Would you mind explaining the use of "default" in your example coldfusion? Other than that, thanks a lot for your example ;) I think I'm going to have to make a sample project with different conditional statements and nested statements and such to get used to them. Oh - Also, since variables defined within scope deliminators are only availible within that scope, what is the proper way to declare a variable that I may need both inside of and outside of an if statement? Up to now I've been putting them after the "static void Main()" function, but not inside any function. Thanks again for your reply!
  4. Hi again all, Sorry for the basic question, but I'm having trouble finding this information. In MSDN and on the various C# Tutorials and websites I've read, they give examples but don't give information on the flow of the program in an if statement in C#. The particular code I'm having trouble with is: do { // get data to perform conditional statement on if (a != b) { if ( c == d ) // do something if ( c != d ) { // do something different } } } while ((a == b) && (a != -1)); MessageBox.Show("Done"); } I want this section of code to loop until either a != b, or a == -1, but it seems it's not looping and I believe this is because of my if statements. To be honest, I'm not sure that much of the above code is correct (it builds, but I think it's not the result I was aiming for) I'm used to VB, where I can do End If to end the if statement, and the program will continue to the line after "End If" - it seems to me that in C# that isn't the case, but since I haven't been able to find much good information I'm not sure. Please could anyone explain how C# if statements work? As I understand it at the moment, the "}" at the end of the statement ends not only the if statement, but the whole function which the code is in (unless a certain result is returned), but I can't figure out how, if that is the case, it works. Any help or links are greatly appreciated - I suppose since this is a basic subject, the info is out there - I've just managed to miss it :mad:
  5. I agree. I'm new to the forum and haven't posted much, but I visit pretty much every day since I found the forum and they've been a huge help. Dosen't stop me from messing up on stupid little mistakes :o, but still - thanks to everyone who offers help here :) Xtreme .NET Talk is by far the friendliest and most helpful .NET forum I've found.
  6. Hi, VBAccelerator.com has a graphics resource section. Go to the icon section of that and they have a good range of icons - including the icons you need I'm sure, as iirc there is an Office section. Here's a link to the Icons page: http://www.vbaccelerator.com/home/Resources/Graphics_Library/Icons/index.asp I think the Office icons are located inside the toolbar section. Hope that helps :)
  7. Heh - I feel so stupid. I found out that the reason that absolutely nothing was working, was that the controls (on the second form) were private. All I had to do was change "private" to "public" and it works fine :o Thanks anyway for the link Plausibly Damp :)
  8. Thanks for the reply PlausiblyDamp. I remember reading that thread when I started VB .NET - but it seems either I'm still missing something after reading it through a few more times, or C++ .NET works in a different way. Trying to pass a string to the forms constructor, as in the example by Bucky in that thread, complains that "function does not take 1 argument". My code for that was: private: System::Void MyMessage(System::String * Notice) { MsgBox *Message = new MsgBox(Notice); Message->ShowDialog(); } The final example in Bucky's thread, I had some trouble with. On my Form1, I put #include "MsgBox.h";, and then put this code to call the messagebox: MsgBox *Message = new MsgBox("foo"); Message->ShowDialog(); At which C++ told me that the first line dosen't accept any arguments. I have tried getting the info from Form1, by using code in MsgBox - but that failed to build. In Form1 I had #Include "MsgBox.h" and in MsgBox I had #Include "Form1.h" but as soon as I tried to build with #Include "Form1.h" in MsgBox, C++ complained about my referance to MsgBox in Form1 regardless of any code I used to reference the other forms. I think that is probably my fault as it seems like you should be able to do that - like I said I'm only 2 days into C++ so I'm only just starting to get used to it.
  9. Hi everyone, I'm new to C++ (2 days :P), and I'm trying to make a function to show a custom MessageBox - I always used to do this in VB6 and VB.NET as imo it looks nicer in certain apps... Anyway, what I'm trying to do is create a function which can be called, and will show a messagebox with the message of your choice (once it's working I'll add icons and such too). What I have so far is: private: System::Void MyMessage(System::String * Notice) { MsgBox *Message= new MsgBox; //Message->lblNotice->Text = Notice; Message->ShowDialog(); } Which could be called like this for example: MyMessage("Hello World!"); My question is about the line that I've commented out. With that line I get the message: "Cannot access private member declared in class 'prjMsgTest::MsgBox'" Is it possible to access properties of controls on other forms, as I've failed to do in the code above? If so can anyone give an example? In VB.NET it would simply be formName.labelName.Text = Notice TIA for any suggestions :D
  10. Using math you can work out the download speed per second, so maybe you could use that to estimate an ETA? Unfortunately math is far from being a strong point for me, so I can't help there :P I'm very sure it is possible though ;)
  11. Your percentage code works perfectly for me. I put it in the downloadChunks function, after the line " pProgress.Value += iBytesRead" and before the line "else" It worked with no problems :) Edit: Regarding the thread problem.. Sorry I totally forgot abotu that. Try taking the line "Dim downloadThread....." with "Public downloadThread As New Thread(AddressOf StartDLThread)" But put that code outside of any function or sub. I think that should fix it :)
  12. Oops - when I typed the code from the top of my head I forgot what I called the thread in my example - try replacing threadName with downloadThread.
  13. Hmm, well I haven't implemented a cancel button yet, but off the top of my head you could put this in a cancel button (it's not tested, mind.. off the top of my head :)) threadName.Abort() 'to kill the thread if file.exists(filePath) then kill(filePath) 'if any of the file has been downloaded, might as well delete it else exit sub end if filePath being the path of the file on your HD. Hope this is of any help - but I think there may be a better way to end the download than just aborting the thread - I'm new to .NET myself. Maybe someone else will be able to give better input on that ;)
  14. I had the same problem in my app - the download was quite big so it froze for a long time. The solution I have used is multithreading. The problem for me here was that afaik you can't start a function as the thread, only a Sub. So the way I've done it is like this: Private Sub cmdDownload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim downloadThread As New Thread(AddressOf StartDLThread) downloadThread.Start() End Sub Sub StartDLThread() DownloadChunks("http://www.rs-sidekick.com/downloads/rs_sidekick_099.msi", pProgress, "Path to Download to") End Sub Function DownloadChunks(ByVal sURL As String, ByVal pProgress As ProgressBar, ByVal Filename As String) 'You already have this function :) End Function Remember if you use this solution to put Imports System.Threading (sorry I can't use the proper VB tags to make it readable, every time I try to use them it puts all of the code onto one line :( ) Hope this helps ;)
  15. This function was posted by someone on this forum, but I can't find the thread so sorry for not being able to give credit :) Function DownloadChunks(ByVal sURL As String, ByVal pProgress As ProgressBar, ByVal Filename As String) Dim wRemote As System.Net.WebRequest Dim URLReq As HttpWebRequest Dim URLRes As HttpWebResponse Dim FileStreamer As New FileStream(Filename, FileMode.Create) Dim bBuffer(999) As Byte Dim iBytesRead As Integer Try URLReq = WebRequest.Create(sURL) URLRes = URLReq.GetResponse Dim sChunks As Stream = URLReq.GetResponse.GetResponseStream pProgress.Maximum = URLRes.ContentLength Do iBytesRead = sChunks.Read(bBuffer, 0, 1000) FileStreamer.Write(bBuffer, 0, iBytesRead) If pProgress.Value + iBytesRead <= pProgress.Maximum Then pProgress.Value += iBytesRead Else pProgress.Value = pProgress.Maximum End If Loop Until iBytesRead = 0 pProgress.Value = pProgress.Maximum sChunks.Close() FileStreamer.Close() Return sResponseData Catch MsgBox(Err.Description) End Try End Function I'm currently writing an updater app for a friend, and this works perfectly for it - it should work fine for you :) sURL is the URL of the file to download, pProgress is the progress bar that you're using, and Filename is the filename to download to. Remember to put imports System.Net, and imports System.IO ;)
  16. Hi, sorry to bring this thread up again - but I have a problem somewhere :( I was working on the routine - getting a progress bar and labels to follow the progress of the extraction etc... And though I've finally got that working properly, it takes *ages* to extract anything. The file that is embedded into my test app is 315kb, and used to extract almost instantly. It now takes around a minute or more. If anyone can spot what my problem is or offer any advice to speed it up, that'd be great.. Also I ought to mention that this routine is running in it's own thread (so my app isn't frozen during the extraction), I don't suppose that could cause a problem? Thanks ! Here's the code - (Edit: I have had to use code ... /code tags, since VB tags put all of the code on one line, making the page unreadable :() Try Dim myAssem As [Assembly] Dim fStream As New FileStream(Application.StartupPath & "\nfo.rar", FileMode.Create, FileAccess.Write) 'InputBox("Dir to extract to", "Extract to-"), FileMode.Create, FileAccess.Write) Dim sw As System.IO.Stream Dim resSize As Long = 0 'The size of the resource Dim resDone As Long = 0 'Amount extracted myAssem = [Assembly].GetExecutingAssembly() sw = myAssem.GetManifestResourceStream("ResExtraction.Test.rar") Dim bbuffer(sw.Length / 1024) As Byte 'Stream buffer resSize = sw.Length lblFilesize.Text = resSize PB.Maximum = resSize PB.Minimum = 0 PB.Step = PB.Maximum / sw.Length '-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Do sw.Read(bbuffer, 0, 1) fStream.Write(bbuffer, 0, 1) 'Update labels, progress bar etc... *********************** resDone = resDone + 1 lblExtracted.Text = resDone PB.PerformStep() PB.Text = PB.Value & "%" '/Updates *************************************************** Loop Until PB.Value = PB.Maximum 'resDone = sw.Length '-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= MsgBox("Extracted!", MsgBoxStyle.Information, "Extraction is complete") cmdExtract.Enabled = True Exit Sub Catch ex As Exception MsgBox(ex.ToString, MsgBoxStyle.Critical, "ResExtraction Error") Exit Sub End Try
  17. Hi For the systemtray icon, use the NotifyIcon control, and set the visibility property to false if you don't want the icon to be in the system tray at all times. In the form_Closing event of your form, put code something along the lines of: e.Cancel = True Me.Hide() NotifyIcon.Visible = True This will hide the form, and make the sys tray icon visible. As for the menu, look at the ContextMenu control - create the menu and remember to add it to the system tray icon (by using the NotifyIcon's ContextMenu property ;) Hope this helps :)
  18. Thanks for all your help IngisKahn, it now works perfectly :) Though the biggest file I tested was 2MB, it seems really fast - though my code could be much better. Anyway, thanks a lot for helping me with this :D
  19. Thanks for that - I get how this should work, but I'm missing something. I used MSDN and this forum, but this is the best I have got so far: Dim myAssem As [Assembly] Dim fStream As New FileStream(Application.StartupPath & "extracted.zip", FileMode.Create, FileAccess.Write) Dim sw As System.IO.FileStream Dim bBuffer() As Byte 'buffer myAssem = [Assembly].GetExecutingAssembly() [u]sw = myAssem.GetManifestResourceStream("ResExtraction.Test.zip")[/u] sw.Read(bBuffer, 0, 100) 'read 100 bytes fStream.Write(bBuffer, 0, 100) 'write an array of 100 bytes The line of code that I've underlined is throwing up the error "An unhandled exception of type 'System.NullReferenceException' occurred in ResExtraction.exe. Additional information: Object reference not set to an instance of an object." Any idea what I've done wrong here? Thanks for the help :)
  20. Hi - thanks for the advice. I've never used FileStream before, but from various forum posts, I've put this together - Dim ASM As [Assembly] Dim fStream As New FileStream(InputBox("Extract to (w/ .rar ext)", "Extract to *.rar"), FileMode.Create, FileAccess.Write) Dim sw As System.IO.FileStream ASM = [Assembly].GetExecutingAssembly() sw = ASM.GetManifestResourceStream("ResExtract.Test.rar") fStream.Write(array() as byte, offset as integer, count as integer) ' sw.Close() Am I going in the right direction here? If so, what is my "array as byte"? I don't really know much about this, so sorry if this is totally wrong or if I use the wrong terms :p - I think I have to convert the .rar resource so a byte array, and said byte array would be the array for fStream.Write() :-\ Also, I'm assuming for the offset, that would simply be 0, and for count, it would be the length of the byte array? Again, sorry if I'm talking crap here, I'm only just starting to look into System.IO :)
  21. Using this thread by Plausibly Damp (http://www.xtremedotnettalk.com/showthread.php?t=83574), and various other threads, I've pretty much got the hang of how to use icons / images and such from resources. One thing I can't figure out is how to save the file - pretty much extracting the file from my apps resource, to the HD. Is there a way to do this, without 'cheating' by setting the image in a picturebox and saving it from there... A method that can work on all filetypes maybe - I'm thinking it would be possible to make a (very basic) installer this way, by adding a compressed archive to the project, then extracting it to a temporary location, then decompressing it (RARLabs, the makers of WinRAR have a RAR decompression control on their site) and then deleting the compressed archive. Registry entries could also be made either in code from the 'installer', or by executing a .reg - I suppose you could make a fairly good installer with some work. Sorry for the long-whinded explanation - and tia for any help ;)
×
×
  • Create New...