|
Image.FromFile is the only method I know of to load a bitmap from a file. Do you have the right dlls imported ? System.Drawing, I believe.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
There are at least three ways of getting an image from a file:
- Image.FromFile()
- Image.FromStream()
- Bitmap(filename) constructor
AFAIK the third one exists on all platforms.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
Hi All,
I am facing a weird kinda problem. Can't figure the solution. Here is the problem.
I have a string "FLAMES". This is a fixed string. I want to start counting the string characters till it reaches the value of an integer 'n' say the value of n = 7.
So what I is want is the code to start counting from F,L,A,M,E,S now at n = 6 the string finishes, so n = 7 will be "F". Now at the last count of n whatever alphabet is there it should get scrapped off. In this case "F" gets scrapped off. The reamining string is "LAMES".
Then restart the count from "L" till n = 7 and this time the alphabet that gets scrapped will be "A", the remaining string is "LMES"
Again restart the count from next character which in this case is "M".
Repeat this procedure untill there is only one alphabet remaining in "FLAMES". In this case of n = 7 it should be "E"
Can anybody help in this? I'm really stuck at this.
Thanks in advance for any help.
Manik
|
|
|
|
|
Sounds like some incredibly simple homework to me. We're not going to do it for you, you have to try yourself. It's set so you can learn, not because the world needs this program to exist. So, what have you tried ? Think about the task, think about how to logically break down the steps you want to take. If you're stuck when you bothered to try yourself, you might post code here and ask a SPECIFIC question.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Here is a tip...
SubString
Steve Jowett
-------------------------
Real programmers don't comment their code. If it was hard to write, it should be hard to read.
|
|
|
|
|
and the Second tip is ...
.... using a loop
|
|
|
|
|
Hey guys okay so im trying to do a Bubble Sort dealing with an array of data that is being loaded at form load from a text file
But right now i keep getting an error everytime it is being executed. I keep getting this error: Index was outside the bounds
of the array!
But i cant see where I am gng wrong?
This is what i am trying to do: my array contains values like this: "C2 H2 SA D4 D2 DA SK S9 S4 HA HQ HK" IT CONTAINS 52 values
all together
Then this is what im trying to sort when the user clicks arrange button: "C2 D2 D4 H2 HQ HK HA S4 S9 SK SA"
PLEASE HELP!!!!!!!!!
Private Sub btnArrange_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnArrange.Click
'*************************************************
'this sub will sort the players cards in increasing
'order using a bubble sort
Dim Last, i As Integer
Dim temp As String
Dim ExchangeMade As Boolean
lblPlayer1.Text = ""
lblPlayer2.Text = ""
lblPlayer3.Text = ""
lblPlayer4.Text = ""
Last = ShuffleCards.cards2.Length - 1
Do
ExchangeMade = False
For i = 0 To Last
If ShuffleCards.cards2(i) > ShuffleCards.cards2(i + 1) Then
'exchange values
temp = ShuffleCards.cards2(i)
ShuffleCards.cards2(i) = ShuffleCards.cards2(i + 1) '*****THIS IS WHERE THE ERROR OCCURS******
ShuffleCards.cards2(i + 1) = temp
ExchangeMade = True
End If
Next i
Last = Last - 1 'decrement length
Loop Until (Not (ExchangeMade = True)) Or (Last = 0)
'DISPLAY SORTED DATA IN EACH LABEL
For i = 0 To ShuffleCards.cards2.Length - 1
lblPlayer1.Text += ShuffleCards.cards2(i)
lblPlayer2.Text += ShuffleCards.cards2(i + 1)
lblPlayer3.Text += ShuffleCards.cards2(i + 2)
lblPlayer4.Text += ShuffleCards.cards2(i + 3)
Next
End Sub
|
|
|
|
|
PAguilar09 wrote: If ShuffleCards.cards2(i) > ShuffleCards.cards2(i + 1) Then
If i counts up to the biggest possible value, when it gets there, is i+1 still inside the array, or not ?
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
well i set breakpoints and saw that as the loop runs my arraylength is 51 since the index value = 51 because there are 52 values total
During the loop i also saw that the values are not being sorted in ascending order it takes the first value in teh array
and tests to see if its in order if not then it should swap.
I am so lost at why this sort wont work??????
|
|
|
|
|
I'm not sure how I can make it clearer. Look at the error message again, then consider if you have 52 items, numbered 0 to 51, and your loop value is 51, and you look for the index at i+1, what will happen.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
So if I am looking at item 51... (because it's a 0 based array, therefore 52 items are indexed 0 to 51), you are saying that if I attempt to look at item 51 + 1 = 52, this might be out of bounds on an array of items indexed 0 to 51?
|
|
|
|
|
Wait - there's a thought !!!
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
If ever there was a first year programming homework question, it's a bubblesort implementation!!
|
|
|
|
|
Yep, and that's precisely why I was trying to lead him to water, rather than provide a direct answer.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
I remember developing a wonderful bit of code for a bubblesort algorithm. Imagine how gutted I was when I discovered that by writing a simple IComparer implementation I could take advantage of the much better bubblesort algorithim built in to .Net.
Just like Microsoft to develop the same code already. Serves me right for not checking the documentation first.
If you have knowledge, let others light their candles at it.
Margaret Fuller (1810 - 1850)
www.JacksonSoft.co.uk
|
|
|
|
|
I hope your tongue gets stuck firmly in your cheek .
|
|
|
|
|
if your going to use a do and a for - then you need to make sure your not exceeding the size of the array. You can't compare if i+1 is greater then getupperbound(0). so you need to test for that.
if you use a for and a for then it will do it for you.
Dim sa() As String = {"a", "z", "e", "b", "j", "k", "o", "c", "d", "r", "n", "i", "t", "u", _
"m", "v", "g", "f", "p", "q", "h", "l", "s", "w", "y", "x"}
Dim Temp As String
For idx1 As Int16 = 0 To sa.GetUpperBound(0)
For idx2 As Int16 = idx1 + 1 To sa.GetUpperBound(0)
If sa(idx2) < sa(idx1) Then
Temp = sa(idx1)
sa(idx1) = sa(idx2)
sa(idx2) = Temp
End If
Next
Next
For idx As Int16 = 0 To sa.GetUpperBound(0)
Debug.Write(sa(idx))
Next
abcdefghijklmnopqrstuvwxyz
'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous
'Life's real failure is when you do not realize how close you were to success when you gave up.' ~ anonymous
|
|
|
|
|
Hi!
I'm cooding an aplicattion that using only my method takes long time to be processed because it has to work with long text files (around 8 MB each file). Tha't because i've decided to take advantatge of multithreading but i don't know how to do that. I thougth in splitting the text file in smaller texts and working with them using the same method in multithreading and parallel so I've written that:
Dim sr = New IO.StreamReader(foundFile) 'i open the text file
Dim lines As Integer = 0
Dim storage(499) As String
While sr.Peek() <> -1 'I read each line
storage(lines) = sr.ReadLine 'i add this line to my array
lines += 1
If lines = 499 Then 'if my array is full i do a new trhead
ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf proceso))'proceso is my method
lineas = 0 'restarting counter...
End If
ThreadPool.GetAvailableThreads(a, b) 'i check how many threads ther are
While a = 0 'if there are the maximum posible trheads i do this while until one threa ends
ThreadPool.GetAvailableThreads(a, b)
End While
End If
When I do the thread it's always the same method. So my problem is that. I need to repeat a method a lot of times but i want do do it in multithreads and parallel because it will be much faster and the program will not freeze with these long files. The problem with this code is that sometimes the threads starts but never ends and also the program ends frezzing it without any result. Why is this happinig? Any better idea to repeat a lot of times a method but using multithreading?
Thanks a lot!
|
|
|
|
|
First, creating that many threads is pointless.
Second, allocating a thread also allocates 1MB of memory to go with it. So, if you actually had one thread running per object and had to process, say, 500 objects at once, you just ate up 500MB of RAM.
Lastly, the largest number of threads you can use and still gain a performance benefit is the number of cores in your processor. Also, a hard drive can only read one area of the disk at a time, so each thread is going to spend alot of time waiting for I/O operations to complete.
I don't know what you're doing with the file so it's difficult to say anything useful. But, if you're reading a line from the file and doing the same processing on each line in the file, you can have one thread read the file, parse it into a work object and place it into a queue. Then you can have worker threads pulling "jobs" out of that queue and processing each item.
|
|
|
|
|
Mmmm it can be interesting... tomorrow i'll try it because now is time to go to sleep
Seriously, because that program is for me and not to sell it I haven't thinked about RAM Anyway, I say you what the program does.
Well what the program does is to take the text that i want of all the text file. In each text file there are a lot of lines and in each line there're some data separated by commas representing they're columns and what i want to do is to take the "columns" i want of each line (well it will be the same columns for all the text file) and then seprate again them by commas and saving in an other text. In other words, i erase the columns i don't want of an input file. That's why i splitted the text every 400 lines because i thougth i'd be useful but if don't how will you do it? If i don't do anything of multitrheading the programs seems that frezees but if you led it it will end the job after a long time but it's much time...
Thanks for your time!
|
|
|
|
|
OK, having read the details now, I would not change a thing on your app.
Look at Task Manager's performance pane and estimate average CPU load, lets say it is about 100%/Q (if Q is large, look again at your single-threaded code; don't use any Q higher than 5).
Now split the files into Q folders, and run Q copies of your app at the same time, each dealing with one folder. That is about the best you will ever get, but now you get it without much ado.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
Some suggestions that may improve performance, and are applicable to a single-threaded or multi-threaded app:
1.
don't use regexes for this, they are powerful however they are slower than simple string logic;
2.
don't use string.Split() if all you need is one part
Hence, use an overload of string.IndexOf() to find the Nth comma; use another IndexOf() to find the next one,
then use string.SubString
BTW: this would fail if fields also have embedded comma's (e.g.within quotes), but so would Split().
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
Hi,
multi-threading will increase overall performance as long as:
1) you have idle cores (e.g. your system is a quad core and there mainly is a single app, which isn't multi-threaded at all)
2) or your active cores are not fully loaded because a lot of time is spent waiting on something (disk I/O, network I/O, etc).
You can check both by looking at the performance pane of Task Manager while your current app executes. If the CPU load is near 100%, threading won't help you at all. If it is near 50% on a dual-core, at best threading will double the speed. etc.
Keep in mind that multi-threading has its drawbacks too:
- an N-core system is not N times as powerful as a single-core, because a lot of resources are shared (main memory, some of the cache, all input/output devices, ...).
- thread synchronization (locks, mutexes, whatever) come at a cost.
Conclusion:
- if your CPU load is way below 100%/N for an N-core system, it is waiting a lot, and more threads may (or may not) remedy that;
- if your CPU has N cores, multi-threading (up to N) may or may not provide a speed increase up to N.
- most often the first thread you add is the biggest step forward.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
Is there any way to turn off the sound in your form?
|
|
|
|
|
Don't start another thread on the same subject. No, there is no way to turn off the sound "globally" for an entire form.
|
|
|
|
|