Author Topic: Total newby to the swamp... VB block insertion  (Read 39065 times)

0 Members and 1 Guest are viewing this topic.

Jeff_M

  • King Gator
  • Posts: 4087
  • C3D user & customizer
Re: Total newby to the swamp... VB block insertion
« Reply #90 on: May 25, 2006, 02:24:16 PM »
Bob, so everytime an option button is clicked the file is re-read? I can see placing each file read into when the option button is selected, but once the array is filled there's no reason to read it again.....This isn't that big a deal for a "Insert one block" routine, but it was mentioned that multiple insertions/selections may be an option.

Jeff_M

  • King Gator
  • Posts: 4087
  • C3D user & customizer
Re: Total newby to the swamp... VB block insertion
« Reply #91 on: May 25, 2006, 02:36:39 PM »
Oh, and I don't want to argue about this, but I want to point out what RR said about Dynamic arrays. This is paraphrased from the class I took from him a few years back:
Quote from: more_or_less
Unless you KNOW you are going to have a small i.e.-less than 20 members, array you should never use ReDim in a loop. It is preferrable to either Redim it first to a value larger than it could possibly ever get to OR Set it to a reasonable number and check to make sure it isn't going to be exceeded with the next useage and increase it another chunk. In both cases a Redim to the final size is required.
I recall this quote solely due to I turned in a solution with a Redim Preserve in a loop and I was quite well chastized for it......

In Tim's case here, he used an initial value of 999 knowing he'd never have that many blocks in the array.

With the speed of today's computers it may not make any difference which method is used, and I can say that I have used all 3 methods without any noticable performance hit or gain.

Bob Wahr

  • Guest
Re: Total newby to the swamp... VB block insertion
« Reply #92 on: May 25, 2006, 02:54:11 PM »
Definitely lots of ways to skin cats and most of them are ridiculous amount of fun.  What the first version is doing with

Dim arrType1() As String

is telling the program that you will be using a variable called arrType1, that it is going to be an array(), and that the values of the array will be strings.  You are not telling the program how many items the array is comprised of just that it is an array.  When you Dim a variable as a string, the program automatically reserves 10 bytes of memory for that variable.  When you Dim something as an Array, you reserve 20 bytes plus 4 bytes per Dimension plus the data size.  This means that right off the bat with the above Dim, you are reserving 34 bytes of memory.  When you do

ReDim arrType1(0 to 999)

you now have 20 bytes for the array + 4 because it is a single dimension Array + (10 * 999) bytes for the reserved strings.  That's a total of 10,014 bytes.  I know that 10k RAM isn't much these days, but you are doing it three times so you have 30k used and the arrays are still empty, their size only goes up from here.  Of course, after you populate them, you are chopping off the unused portion and therefore freeing the memory back up but it is still being used for no reason for a while.  What I proposed is that you ReDim the array to be one item longer everytime you are going to add an item so that the array is always the length that you need.  By way of example, the strings in the txt file are 35 characters long.  Even though block names will vary I'm sure, lets go with 35 for the example.  If there were 100 blocks in each list, with the way you were doing it you would have:

10,014 bytes reserved for the array
35 characters X 2 bytes per character X 100 blocks in the list or 7000 bytes
17,014 bytes X 3 arrays
51,042 bytes total used to populate the three lists

Still not an enormous amount but compared with 8,024 bytes to fill one list as needed and you can see that it starts to add up.

Next with the way you had it, after you were finished populating the array, you were cropping it with

Redim Preserve arrType1(0 to I - 1)

followed by redimming one dimension the arrName array the same way which ends up making the first dimension of arrName the same length as arrtype.  With my suggestion, instead of using I - 1 to set the ubound, since arrType is set as we went and is the right length, so we use the ubound of arrType to set the ubound of the first dimension of arrName.

Let me know if this actually makes sense to you because I was really feeling like I was starting to talk in circles.

Bob Wahr

  • Guest
Re: Total newby to the swamp... VB block insertion
« Reply #93 on: May 25, 2006, 02:57:24 PM »
Bob, so everytime an option button is clicked the file is re-read? I can see placing each file read into when the option button is selected, but once the array is filled there's no reason to read it again.....This isn't that big a deal for a "Insert one block" routine, but it was mentioned that multiple insertions/selections may be an option.
Good point.  I initially changed it to have the populate list routines as separate Subs then changed again to be in the click sub.  Would be easy to check and see if the array was empty and only populating it if so.

Bob Wahr

  • Guest
Re: Total newby to the swamp... VB block insertion
« Reply #94 on: May 25, 2006, 03:00:01 PM »
Oh, and I don't want to argue about this, but I want to point out what RR said about Dynamic arrays. This is paraphrased from the class I took from him a few years back:
Quote from: more_or_less
Unless you KNOW you are going to have a small i.e.-less than 20 members, array you should never use ReDim in a loop. It is preferrable to either Redim it first to a value larger than it could possibly ever get to OR Set it to a reasonable number and check to make sure it isn't going to be exceeded with the next useage and increase it another chunk. In both cases a Redim to the final size is required.
I recall this quote solely due to I turned in a solution with a Redim Preserve in a loop and I was quite well chastized for it......

In Tim's case here, he used an initial value of 999 knowing he'd never have that many blocks in the array.

With the speed of today's computers it may not make any difference which method is used, and I can say that I have used all 3 methods without any noticable performance hit or gain.
I don't remember that but it wasn't my chastizement and he does have a way of making you remember when you do something in a way other than the best way.
Quote
In Tim's case here, he used an initial value of 999 knowing he'd never have that many blocks in the array.
never say never

akdrafter

  • Guest
Re: Total newby to the swamp... VB block insertion
« Reply #95 on: May 25, 2006, 08:27:41 PM »
Okie dokie. Check it out. I have attached the code as I think it is a bit long to be posting anymore.

There has been a function added to "search" the support paths...way cool....and thanks to "E"(not sure he wants to be named...hahahaah), he knows who he is.

Anyway. The routine appears to be working. So now, I think I am going to dress up the GUI a bit while I think of what other "options" would be useful.

Thank you Bob & Jeff.

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: Total newby to the swamp... VB block insertion
« Reply #96 on: May 26, 2006, 10:01:41 AM »
Elmo?
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

Bob Wahr

  • Guest
Re: Total newby to the swamp... VB block insertion
« Reply #97 on: May 26, 2006, 11:06:18 AM »
I remember that search function.  It was the first of if I remember correctly 2 functions that were my extremely badly failed attempt at getting people to provide similar functionality between lisp and VBA over at CAD Vault.  I did this one, and someone, I think maybe Kerry although it could have been Stig but was probably someone else entirel, posted a lisp function.  Then it went down in a hail of bullets and bad feelings.  Good times that.  Either way, this Elmo guy jacked my function.  Bastard.

As for dressing up the IDE, how can you do more than you already have?  Seriously though, you mentioned adding fuctionality to change the layer to an exiting layer so a checkbox for that might in order.  It would also be nice to have a preview pane.  No matter how descriptive a block's name is, somebody is going to be unable to figure out what it is without a picture.  A layer override might be a good idea.  I know that occasionally I will want/need to use a typically plan symbol in a detail and insert it, then change the layer.  You could do this with either a textbox to type the layer, or a combobox that lists detail layers.

Just throwing out ideas here, not trying to drive.

akdrafter

  • Guest
Re: Total newby to the swamp... VB block insertion
« Reply #98 on: May 26, 2006, 12:46:57 PM »
Bob,

Elmo? Nice.  :-D I am sure he likes that one. As far as your code going down in a hail of bullets, the code must have been wearing a BPV because it survived and I think it works very nicely. Why do I say that, well... it works. I can be pretty simplistic like that, but a fair amount of time simple is better.

So, movin on....

There are things I would like to add like:

displaying the current dimscale(Got this one, just have not added it to the GUI yet)

a check on the "insunits"(what a pain this one can be) freaks me out when I think a block should be inserted a certain size and the "insunits" are set to feet and the block I am inserting comes in haaaaauuuugggeeeee. I think "insunits" set to "0" would be best..... a check of, store value, switch to 0, and after completion a restoration of the original "insunits" value.

Yes.... a check box for "Existing" (layer)

Yes... Preview pain, not sure how to tackle that one. I mean, I have heard of a couple of different ways of doing it but not sure which makes the most sense. Relying on an separate program is not one that I find appealing. Slides? would it work? Bitmap's/Png's...that could create a lot of extra files. Will have to explore that one in depth a little further.

Layer overide... I had not thought of that one and I do insert some of these "Plan" blocks into "Detail" sheets. Good thought. Maybe another check box for "Details" with the default on start up being "Plan". I think on that one.... simply checking a "Details" check box that would then read a text file like it is already doing, with the layers defined that way. Open to suggestions though.

So.....yeah.... lots of ideas and all are great and appreciated. Keep em comin.

Thanks.


David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: Total newby to the swamp... VB block insertion
« Reply #99 on: May 26, 2006, 01:18:57 PM »
Yes... Preview pain, not sure how to tackle that one. I mean, I have heard of a couple of different ways of doing it but not sure which makes the most sense. Relying on an separate program is not one that I find appealing. Slides? would it work? Bitmap's/Png's...that could create a lot of extra files. Will have to explore that one in depth a little further.
bitmaps stored in a DLL file would work.  Then you would only need to keep up with 1 file
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

akdrafter

  • Guest
Re: Total newby to the swamp... VB block insertion
« Reply #100 on: May 26, 2006, 01:37:58 PM »
Cmdr,

I tried the bitmaps in a dll once....learned how to do it from Afralisp... and it worked fine here in this office but for whatever reason our other office had continual problems with it. I am not sure why but I think it might have had something to do with permissions on their server...me not having sufficient permissions. Anyway, I think you are right though a bitmap dll would be a good way to go.

Thanks for the input.

Bob Wahr

  • Guest
Re: Total newby to the swamp... VB block insertion
« Reply #101 on: May 26, 2006, 01:55:55 PM »
Bob,

Elmo? Nice. :-D I am sure he likes that one. As far as your code going down in a hail of bullets, the code must have been wearing a BPV because it survived and I think it works very nicely. Why do I say that, well... it works. I can be pretty simplistic like that, but a fair amount of time simple is better.

So, movin on....

There are things I would like to add like:

displaying the current dimscale(Got this one, just have not added it to the GUI yet)

a check on the "insunits"(what a pain this one can be) freaks me out when I think a block should be inserted a certain size and the "insunits" are set to feet and the block I am inserting comes in haaaaauuuugggeeeee. I think "insunits" set to "0" would be best..... a check of, store value, switch to 0, and after completion a restoration of the original "insunits" value.
Good idea.  This should get 'er
Code: [Select]
Public intInsUnits As Integer

Private Sub UserForm_Initialize()
  intInsUnits = ThisDrawing.GetVariable("INSUNITS")
  ThisDrawing.SetVariable "INSUNITS", 0
  OptionButton1.Value = True
End Sub
Private Sub UserForm_Terminate()
  ThisDrawing.SetVariable "INSUNITS", intInsUnits
End Sub
Quote
Yes.... a check box for "Existing" (layer)

Yes... Preview pain, not sure how to tackle that one. I mean, I have heard of a couple of different ways of doing it but not sure which makes the most sense. Relying on an separate program is not one that I find appealing. Slides? would it work? Bitmap's/Png's...that could create a lot of extra files. Will have to explore that one in depth a little further.
Cat skinning and where to start

Quote
Layer overide... I had not thought of that one and I do insert some of these "Plan" blocks into "Detail" sheets. Good thought. Maybe another check box for "Details" with the default on start up being "Plan". I think on that one.... simply checking a "Details" check box that would then read a text file like it is already doing, with the layers defined that way. Open to suggestions though.
that could work.
Quote

So.....yeah.... lots of ideas and all are great and appreciated. Keep em comin.

Thanks.


Oh, I will.
« Last Edit: May 26, 2006, 02:03:31 PM by Bob Wahr »

akdrafter

  • Guest
Re: Total newby to the swamp... VB block insertion
« Reply #102 on: May 26, 2006, 02:17:29 PM »
Ok, looking at that code snippet learned me somethin....

 intInsUnits = ThisDrawing.GetVariable("INSUNITS")
 ThisDrawing.SetVariable "INSUNITS", 0


The above is the VBA equivalent of a lisp type thang....(setq YADDA(getvar "INSUNITS"))

Private Sub UserForm_Terminate()
 ThisDrawing.SetVariable "INSUNITS", intInsUnits
End Sub

This is how I would "restore" all of those things that get tweaked at run time?

Bob Wahr

  • Guest
Re: Total newby to the swamp... VB block insertion
« Reply #103 on: May 26, 2006, 02:23:04 PM »
The above is the VBA equivalent of a lisp type thang....(setq YADDA(getvar "INSUNITS"))
exactly
Quote

Private Sub UserForm_Terminate()
 ThisDrawing.SetVariable "INSUNITS", intInsUnits
End Sub

This is how I would "restore" all of those things that get tweaked at run time?
It's definitely one way.  Someone on CAD Vault made a variable save/restore class.  I think it was mmelone although I have a nagging feeling that it was Paul Marshall.  Maybe both, I can't remember.  I'll see if I can dig it up though.  If it's more than a handful of system variables that your changing, the class would probably be a better way.

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: Total newby to the swamp... VB block insertion
« Reply #104 on: May 26, 2006, 03:24:31 PM »
If it's more than a handful of system variables that your changing, the class would probably be a better way.
Id be interested in seeing that.  I have one for LISP, but one for VBA would be sweet
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)