Friday, June 29, 2012

Updating Code to VB.Net

I am building in VB.Net to try to get around the overflow error. Also, as the application gets bigger, it is better to build in in Visual Studio rather than using VBA.

The following site has links for access the binary file using VB.Net

Thursday, June 28, 2012

STL Files: Reading the Number of Triangles in VBA

The file format for the STL file is described at

It states that the number of triangles is and unsigned 32 bit integer. Unsigned integers are not a native data type in VB. So what needs to be done is convert a Long signed integer into an unsigned integer. Microsoft has a good description of this at

The key function that needs to be used is:

      Private Const OFFSET_4 = 4294967296#

      Function LongToUnsigned(Value As Long) As Double
        If Value < 0 Then
          LongToUnsigned = Value + OFFSET_4
          LongToUnsigned = Value
        End If
      End Function
The code to read the number of triangles then is:
Sub ReadBlockStl()
    Open "C:\Block.STL" For Binary Access Read As #1
    Dim NumOfTrian As Long
    Get #1, 81, NumOfTrian
    Close #1
    MsgBox LongToUnsigned(NumOfTrian)
End Sub

This code worked find on a cube that had 12 triangles.

However, I tried it on an object that 33924 triangles and I got an overflow error on a for-loop for NumOfTrian. Of course, NumOfTrian is a Long with a maximum positive value of 32768. But when I used a double precission, I still get the same overflow error.

STL Files: Opening an STL file for reading in VBA

STL files when they are stored from solidworks are in Binary format. Thus, VB needs to open a binary file for reading.

The general format of the open command is:

Open pathname For mode [Access access] [lock] As [#]filenumber [Len=reclength]

The format of this command that I used was:

Open "C:\Block.STL" For Binary Access Read As #1

With that, I opened a file located at C:\Block.STL for Binary mode and I associated it with file #1.

Sunday, June 3, 2012

The crash of the Eurozone and why it makes sense for contries to have their own currency

Greece is currently in the throws of anquish as it looks at the cliff edge of falling off the eurozone.

Why did all these contries ban together and create the Eurozone in the first place. They were trying to compete against the strength of the U.S. dollar. They had a dream of becoming world super-power and world dominant economy. For a couple of years it was going great, but now the problems are showing up and we look back to why contries have their own currency. Before currency existed, there was gold. Gold has consistent value all over the world (give or take a bit of transportation costs). This worked well for global trade.

After a while they got tired of lugging gold all over the world to make a transaction, so they resorted to gold backed securities. The countries would keep the gold in the bank and issue notes representing the gold. That is why Fort Knox exists - to hold all the gold which is to back the U.S. Dollar. After a while, countries gave up this idea of having a gold backed currency. One very strong example of this is the hyper-inflation in Germany. This happened because the government took liberty to print money as their way to finance their activities rather than taking on debt or taxation. This type of problem has also happened in South America multiple times.

Over time, hopefully countries are begining to wisen up and realize that printing to much money destroys their country. It is a lesson that a country can learn - because it has to face its own consenquences of being irrisponsible with its ficsal policies.

That is the exact problem with one Eurozone currency. Countries do unwise fiscal acts like Greece's deception to the rest of the world about its actual debt level, and they expect the other countries to bail them out. Greece for many years was riding of cheap debt that was offered it because it was part of the Eurozone and it began to finance many of its activities using increasing levels of debt rather than taxation. It was spending more many than it was making off its citizens and going deeper in the whole as a result. They were able to keep doing this for a sustained period of time because the rating agencies such as Moody's still gave them good debt ratings because they were part of the Eurozone.

This is an example of disconnect between individual countries making fiscal policy decisions, and the Eurozone as a whole having to take responsiblity for those decisions. Now the rest of the world is realizing how fiscally irresponsible Greece has been over the past few years (much like Germany was back in the 1920's), and they want to have no part of it. Germany had to learn it lesson and get it's hand slapped by the rest of the world. Now it is the strongest economy in Europe. If Germany was not shielded from the consequences of its actions, why should Greece be?

I know that the bleeding heart sociallists amonst us do not want to see anyone suffer. However, there has to be some balance between helping people think for themselves and act wisely, and giving a helping hand. I do not hear stories of rampant deaths occuring in Greece because their current crisis.

We should let Greece spread its own wings and figure out how to fly on its own again. It it the oldest country in europe - I think that it can draw on its years of wisdom to figure out how to handle itself in this situation.

Solidworks macros eith ChatGPT

 Record a simple using thr Solidworks macro recorder, upload it to ChatGPT, and explain to ChatGPT how you want it changed:  https://youtu.b...