TylerTCF Light Poster

I was wondering if anyone could help me out with a problem I've had for a few days. This is a code snippet of a program I'm writing to move and delete email attachments from one or more selected emails. Everything works great except the program won't edit the body of the emails as written. When I interrogated in the editor, I found that the MailItems are empty upon initialization and after passed to the sub routine. Any idea why an email I know has text comes up with no body or HTMLBody in Outlook VBA? Thanks in advance.

Public Sub SaveAttachments()
    Dim objOL As Outlook.Application
    Dim pobjMsg As Outlook.MailItem 'Object
    Dim objSelection As Outlook.Selection

    ' Get the path to your My Documents folder
    strFolderpath = CreateObject("WScript.Shell").SpecialFolders(16)
    On Error Resume Next

    ' Instantiate an Outlook Application object.
    Set objOL = CreateObject("Outlook.Application")

    ' Get the collection of selected objects.
    Set objSelection = objOL.ActiveExplorer.Selection

    For Each pobjMsg In objSelection
        SaveAttachments_Parameter pobjMsg
    Next

ExitSub:

    Set pobjMsg = Nothing
    Set objSelection = Nothing
    Set objOL = Nothing
End Sub

Public Sub SaveAttachments_Parameter(objMsg As MailItem)
    Dim objAttachments As Outlook.Attachments
    Dim i As Long
    Dim lngCount As Long
    Dim strFile As String
    Dim strFolderpath As String
    Dim strDeletedFiles As String

    ' Get the path to your My Documents folder
    strFolderpath = CreateObject("WScript.Shell").SpecialFolders(16)
    On Error Resume Next

    ' Set the Attachment folder.
    strFolderpath = strFolderpath & "\OLAttachments\"

        ' Get the Attachments collection of the item.
        Set objAttachments = objMsg.Attachments
        lngCount = objAttachments.Count

        If lngCount > 0 Then ...

TylerTCF

Thank you so much! This was a great catch. Must have been the late night and I dind't know about option explicit. Good tip!

TylerTCF

Changed the name of the sub and eliminated lines 30 and 31. I had those these to see if I was missing something. VBA still skipping the loop. Breakpoints work up to the for loop. But any breakpoint in the loop has no effect and the program proceeds to End Sub with no errors. Weird...

TylerTCF Light Poster

Hi Everyone. It's been a while since I was on here last, but ran into an interesting problem with a nested for loop that I cannot solve. Hoping someone here will know the answer. I placed breakpoints in my code at the For x=1 to 10 line and after to see where run-time is ending. For some reason VBA is not executing the loop at all. Does anyone know what I'm missing? Thanks in advance.

sub help()
Dim x As Integer
Dim y As Integer
Dim lastcell As Long
Dim ws As Worksheet
Dim wscurr  As Worksheet
Dim gcounter As Long
Dim hcounter As Long
Dim num10000(1 To 10) As Double

Set ws = Sheets("ECLMadj")
Set wscurr = Sheets("10000-yr")
wscurr.Select
Range("A265536").End(xlUp).Select
lastcell = ActiveCell.Row
Range("A1").Select

num10000(1) = 2210
num10000(2) = 2220
num10000(3) = 2230
num10000(4) = 2240
num10000(5) = 2250
num10000(6) = 2310
num10000(7) = 2320
num10000(8) = 2330
num10000(9) = 2340
num10000(10) = 2350

gcounter = 1
x = 1
y = 1

For x = 1 To l0
hcounter = 1
  For y = 2 To lastcell
  wscurr.Select
      If Range("A" & y).Value = num10000(x) And Range("B" & y).Value >= 12 And Range("C" & y).Value <= 39 Then
         wscurr.Range("A" & y & ":F" & y).Copy Destination:=ws.Range(Cells(hcounter, gcounter))
         hcounter = hcounter + 1
      End If
  Next y
  gcounter = gcounter + 8
Next x
End Sub

TylerTCF

I removed the width requirement and works fine now. Many thanks. TR

TylerTCF Light Poster

Can someone tell me why it might be that my Title 1 and Title 2 wrap in the table? This is a snippet of 130 titles, some are long, some are short. I want the title block to be a fixed length and nicely formatted. Any suggestions? Thanks in advance.

[CODE=html] PROJECT LISTING OF THINGS

PROJECT LISTING

for

AFRICA

For a copy of any documents listed below, please read the security notice and follow the links to contact me PROJECT TYPE CRITERIA CRITIERIA TITLE DATE ISSUED WHERE 1 Facsimile Title 1 2/16/1999 WHERE 2 Report Title 2 4/19/1999 [/CODE]

TylerTCF

Hey,

I read your post about using the curl library. Can you help me figure out what you meant when you wrote,

[QUOTE=madmaze;1019584]
to include the right libs when linking type:
[CODE]
$curl-config --libs
-lcurl -lidn -llber -lldap -lrt -lgssapi_krb5 -lgssapi_krb5 -lz -lgnutls
$
[/CODE]

and it will display all the needed libs[/QUOTE]

I am using VC++ 6.0 in XP. I am hoping to use the curl library to open 100000 http pages and save the results. Any help is appreciated.

TylerTCF

[QUOTE=mybluehair;756449]I got a snippet off the web of how to download a file from online in c++ console with the curl library. so I installed curl, and copied the code snippet, but it doesnt work. Can someone show me whats wrong?

[code]#include <curl/curl.h>

include

// link with libcurl. eg.
// g++ -Wall -std=c++98 -pedantic -Werror -lcurl -I /usr/local/include -L /usr/local/lib

void get_page( const char url, const char file_name )
{
CURL* easyhandle = curl_easy_init() ;

curl_easy_setopt( easyhandle, CURLOPT_URL, url ) ;

std::FILE* file = std::fopen( file_name, "w" ) ;
curl_easy_setopt( easyhandle, CURLOPT_WRITEDATA, file ) ;

curl_easy_perform( easyhandle );

curl_easy_cleanup( easyhandle );
}

int main()
{
get_page( "www.research.att.com/~bs/",
"/tmp/stroustrup_home_page.html" ) ;
}[/code]

and heres the error:

so does anyone know whats wrong? many thanks. :)[/QUOTE]

I have the same problem and the same question. Anyone use CURL?

TylerTCF

[QUOTE=Clinton Portis;1076261]Many have recommended the [URL="http://developers.curl.com/userdocs/CurlDocs.htm"]curl library[/URL] for applications that need to interface with the net.[/QUOTE]

Thanks for your suggestion. Have you been able to successfully compile a cpp using CURL? I'm getting many compile errors. Did you just use the .exe version or a different version? I tried to compile their example...no luck.

Sorry, for the many questions, just new to this type of development.

*sigh I thought this would be simpler....

TylerTCF Light Poster

Hey Everyone,

I have developed a program to help me geocode approximately 100,000 addresses from Google. After doing some i/o to bring all the names into a vector in C++, I have now 100,000 distinct addresses that I must pull up, retrieve the code from google's server via csv output, and then put the csv information into a string (it's very short because it's just lat/long information and an error code). Is there any way to pull up each of these hyperlinks? I am good with non-network programming, but am unfamiliar with how to do this in C++. VBA via Excel fails to accomplish this task in under 4 hours (for 5k). I would like to be able to do this via C++ (initial sorts took 1/30th of the processing time) from now on as I will have several hundred thousand more to do soon. If someone could point me to some documentation or code snippets, I would love you forever....Many Thanks.

Tyler

TylerTCF Light Poster

I have commented the problem into the code below. See the Store2 vector in the Write Data function. I get error 0xC0000005: Access Violation with no warnings. Any help figuring out why would be appreciated.

[ICODE]

include
include
include
include
include
include

using namespace std ;

struct Weather
{
int winddr;
double windsp;
double ETTsea;
double Hsea;
double VMDsea;
double ETTswell;
double Hswell;
double VMDswell;
double Hs;
};

struct Found {
double height;
double degrees;
double prob;
double count;
};

struct Found2 {
double height;
double VMDsea;
double VMDswell;
int yes;
};

//-----------------------------------------------------------------------------------------------------------------------------
void Write_Data(vector Data) {

double count, y, z, angle1, angle2, count2;
int x, a, b;
Found Temp;
Found2 Temp2;
vector Store;
vector Store2;

count2 =0;

for (b=0; a<Data.size(); a++) {
  Temp2.height =0;
  Temp2.VMDsea =0;
  Temp2.VMDswell =0;
  Temp2.yes=0;
  Store2.push_back(Temp2);
}//for statement

for (y=0; y<=20.0; y = y+.5) {
if (angle1=0 && Data[x].Hs <= y)
count2 = count2+1;

Temp.count = count2;
Temp.degrees = 0;
Temp.height = y;
Temp.prob = count2/105192.0;
count2 = 0;
Store.push_back(Temp);
  for (z=15; z<=180.0; z = z + 15.0) {
      count =0;
      for (x=0; x<Data.size(); x++) {     
        angle1 = abs(Data[x].VMDsea - Data[x].VMDswell);
        angle2 = abs(360-angle1);
        if (angle1>180.0) {
            angle1=angle2;
        } //for if
        if (angle1> z-15 && angle1 <=z && Data[x].Hs <= y) {
            count = count +1;
            if (y==20) {
        Temp2.height =Data[x].Hs;
        Temp2.VMDsea =Data[x].VMDsea;
                    Temp2.VMDswell =Data[x].VMDswell;
        Temp2.yes=1;
 //THIS IS WHERE PROGRAM ERRORS WITH 0xC0000005: Access Violation
                                            Store2[x] = Temp2;
            } //for if
        } //for if
      }  //for ...

TylerTCF Light Poster

Is it legal to have a vector of struct to be returned as the output of a user-defined function? I can't seem to get it to work? Thanks.

TylerTCF

Thanks!

TylerTCF

On second thought, your code worked...do I still need the ostringstream line? I'm trying to figure out what the istringstream and ostringstream did for me...Thanks.

TylerTCF

[CODE]

include
include
include
include
include

using namespace std ;

struct Weather
{
string date;
string time;
double wind;
};

struct Weather2 {
string date;
string time;
double wind_obs;
double wind_sensor;
};

int main()
{
int a =0, i=0,j=0;
string DataStream1;
string DataStream2;
string DataStream3;
vector Sensor;
vector Observations;
vector Search;
Weather2 Found;

cout<<"Pulling in data...Please wait...."<<endl;
ifstream DataFile1("Wind Sensor Data.txt");
while(getline(DataFile1, DataStream1))
{
istringstream Incoming(DataStream1);
Weather w;
Incoming >> w.date >> w.time >> w.wind;
Sensor.push_back(w);
}

ifstream DataFile2("Wind Observation.txt");
while(getline(DataFile2, DataStream2))
{
istringstream Incoming(DataStream2);
Weather x;
Incoming >> x.date >> x.time >> x.wind;
Observations.push_back(x);
}
cout<<"Checking data...Please wait...."<<endl;
for(i= 0; i < Sensor.size(); i++) {
for (j=0; j <Observations.size(); j++) {
if ((Sensor[i].date==Observations[j].date) && (Sensor[i].time==Observations[j].time)) {
Found.date = Sensor[i].date;
Found.time = Sensor[i].time;
Found.wind_obs = Observations[j].wind;
Found.wind_sensor = Sensor[i].wind;
Search.push_back(Found);
}

  }                 

}

ofstream DataFile3("C:\Documents and Settings\ttrusse\Desktop\Algeciras\C++\results.txt");
cout<<"Writing...Please wait...."<<endl;
for (a=0; a<Search.size(); a++) {
cout<<Search[a].date<<" "<<Search[a].time<<" "<<Search[a].wind_obs<<" "<<Search[a].wind_sensor<<endl;
ostringstream Outgoing(DataStream3);
Outgoing << Search[a].date << Search[a].time << Search[a].wind_obs <<Search[a].wind_sensor<<endl;
};
return 0;
}
[/CODE]

TylerTCF

Thanks for the recommendations vijayan...I did move the return 0 in my code, just not on the post. Thanks for the other recommendations, seemed alot more robust as mentioned. I will give that a try.

TylerTCF

What I ended up doing was modifying the data and eliminating the need for the "otherstuff" string. It was causing a headache. Would still be interested in knowing why that was causing so much trouble...

TylerTCF

How can I make it output to DataFile3? Thanks!

TylerTCF

Figured out part of the problem...the program didn't like my data file header, so I deleted it...I used the call stack to figure that out...By the way, anyone that doesn't know about the Call Stack (Alt-7), it is a great tool to help you figure out what you missed in the debug!

TylerTCF Light Poster

Anyhelp with the ostringstream and datastream line would be appreciated. Can't seem to get the data to actually write to the text file...No data in results.txt, but the file is created by the program when I run it...

[CODE]
ofstream DataFile3("results.txt");
cout<<"Writing...Please wait...."<<endl;
for (a=0; a<Search.size(); a++) {
cout<<Search[a].date<<" "<<Search[a].time<<" "<<Search[a].wind_obs<<" "<<Search[a].wind_sensor<<endl;
ostringstream Outgoing(DataStream3);
Outgoing << Search[a].date << Search[a].time << Search[a].wind_obs <<Search[a].wind_sensor<<endl;

[/CODE]

TylerTCF

It is not a compiler error. It is a "Unhandled exception in my.exe (Kernel32.dll): 0xE06D7363: Microsoft C++ Exception...I am using Microsoft VC++ 6.0...Thanks.

What I want to happen is that the data stream coming in is broken into the components on the first line of "Incoming". Then I want the rest of the stream from that line of data to be placed into the component "otherstuff"...The "otherstuff" part of the struct is what's giving me the exception...

TylerTCF

Help? Can't get this substr to work...

[CODE]

include
include
include
include
include

using namespace std ;

struct Weather
{
int years;
int months;
int days;
int hours;
int windr;
double windsp;
double gust;
double waveht;
double waveperiod;
string otherstuff;
};

int main()
{
int a =0, i=0,j=0;
string DataStream1;
string DataStream2;
string DataStream3;
vector Earlier;
vector Later;
vector Search;

cout<<"Pulling in data...Please wait...."<<endl;
ifstream DataFile1("Earlier.txt");
while(getline(DataFile1, DataStream1))
{
cout<<"ok"<<endl;
istringstream Incoming(DataStream1);
Weather w;
Incoming >> w.years >> w.months >> w.days >> w.hours >> w.windr >> w.windsp >> w.gust >> w.waveht >> w.waveperiod;
//HERE IS THE ERROR BELOW...
w.otherstuff = DataStream1.substr(Incoming.tellg());
//****/
Earlier.push_back(w);
return 0;
}
}
[/CODE]

TylerTCF

Just that it didn't recongnize 'C' or 'D' etc in the file path...For some reason though, there is still no output in the results.txt. The cout was added to make sure that the Search vector was filled up (it was)...now if it would just output, it'd be all done...any help again? Thanks in advance.

[CODE]
ofstream DataFile3("C:\Documents and Settings\ttrusse\Desktop\Algeciras\C++\results.txt");
cout<<"Writing...Please wait...."<<endl;
for (a=0; a<Search.size(); a++) {
cout<<Search[a].date<<" "<<Search[a].time<<" "<<Search[a].wind_obs<<" "<<Search[a].wind_sensor<<endl;
ostringstream Outgoing(DataStream3);
Outgoing << Search[a].date << Search[a].time << Search[a].wind_obs <<Search[a].wind_sensor<<endl;

[/CODE]

TylerTCF

Still have a problem. The data file has no data in it. Code is attached below. Any recommendation with this?

[CODE]

include
include
include
include
include

using namespace std ;

struct Weather
{
string date;
string time;
double wind;
};

struct Weather2 {
string date;
string time;
double wind_obs;
double wind_sensor;
};

int main()
{

int a =0, i=0,j=0;

string DataStream1;
string DataStream2;
string DataStream3;

vector Sensor;
vector Observations;
vector Search;

Weather2 Found;

cout<<"Pulling in data...Please wait...."<<endl;
ifstream DataFile1("Wind Sensor Data.txt");
while(getline(DataFile1, DataStream1))
{
istringstream Incoming(DataStream1);
Weather w;
Incoming >> w.date >> w.time >> w.wind;
Sensor.push_back(w);
}

ifstream DataFile2("Wind Observation.txt");
while(getline(DataFile2, DataStream2))
{
istringstream Incoming(DataStream2);
Weather x;
Incoming >> x.date >> x.time >> x.wind;
Observations.push_back(x);
}
cout<<"Checking data...Please wait...."<<endl;
for(i= 0; i < Sensor.size(); i++) {
for (j=0; j <Observations.size(); j++) {
if ((Sensor[i].date==Observations[j].date) && (Sensor[i].time==Observations[j].time)) {
Found.date = Sensor[i].date;
Found.time = Sensor[i].time;
Found.wind_obs = Observations[j].wind;
Found.wind_sensor = Sensor[i].wind;
Search.push_back(Found);
}

  }                 

}

ofstream DataFile3("C:\Documents and Settings\ttrusse\Desktop\Algeciras\C++\results.txt");
cout<<"Writing...Please wait...."<<endl;
cin.get();
for (a=0; a<Search.size(); a++) {
ostringstream Outgoing(DataStream3);
Outgoing << Search[a].date << Search[a].time << Search[a].wind_obs <<Search[a].wind_sensor<<endl;
};

return 0;
}

[/CODE]

TylerTCF

Thanks!

TylerTCF Light Poster

Thanks for your help earlier with the file input everyone...I have another question to ask of you. I am trying to check two vectors against each other to see if the "timeanddate" match up. Then try to output the ones that do match. I am getting errors from the if statement down, as the inputting works flawlessly. Any help would be great! Thanks in advance.

[CODE]

include
include
include
include
include

using namespace std ;

struct Weather
{
string timeanddate;
double wind;
double windmax;
};

struct Weather2 {
string timeanddate;
string excel;
string date;
string time;
int windr;
double wind;
double windmps;
};

struct Golf {
string timeanddate;
double wind_obs;
double wind_sensor;
};

int main()
{

int a =0, i,j;

string DataStream1;
string DataStream2;
string DataStream3;

vector Sensor;
vector Observations;
vector Search;

Golf Foundb;

ifstream DataFile1("Wind Sensor Data.txt");
while(getline(DataFile1, DataStream1))
{
istringstream Incoming(DataStream1);
Weather w;
Incoming >> w.timeanddate >> w.wind >> w.windmax;
Sensor.push_back(w);
}

ifstream DataFile2("Wind Observation.txt");
while(getline(DataFile2, DataStream2))
{
istringstream Incoming(DataStream2);
Weather2 x;
Incoming >> x.timeanddate >> x.excel >> x.date >> x.time >> x.windr >> x.wind >> x.windmps;
Observations.push_back(x);
}
\HERE BEGINS THE PROBLEM...

for(i= 0; i <= Sensor.size(); i++) {
for (j=0; j <=Observations.size(); j++) {
if (Sensor[i].timeanddate==Observations[j].timeanddate) {
Foundb.timeanddate = Sensor[i].timeanddate;
Foundb.wind_obs = Observations[j].wind;
Foundb.wind_sensor = Sensor[i].wind;
Search.push_back(Foundb);
}
}
}

ofstream DataFile3("C:\Documents and Settings\ttrusse\Desktop\Algeciras\Matchup.txt");
for (a=0; a<=Search.size(); a++) {
ostringstream Outgoing(DataStream3);
Outgoing << Search[a].timeanddate << Search[a].wind_obs <<Search[a].wind_sensor<<endl;
}

return 0;
}

[/CODE]

[B]Debug Window Shows...

Loaded 'ntdll.dll', no matching symbolic ...

TylerTCF Light Poster

As you can see below, I am working on making a macro that compares the time in one column on a page to another on a page. However, in the if statement where I'm trying to round the numbers with time values in it (because I need the numbers to match exactly in order for the if statement to work), I am getting a type mismatch error. Does anyone know a smarter way to code if one cell = another cell with time in it? I would use Vlookup but it is having trouble because the time values do not exactly equal each other...help?

Time on difference page is in 10 min increments...
Time on Obs at 0050Z page is hourly on the 50th minute...

[CODE]

Sub Get_Obs_To_Difference()

'
Dim TTR, TTR2, lastcell, bottom As Integer

Sheets("Difference").Select

'Initialize variables
lastcell = 12500
bottom = 1
counter = 0

'Go through the Date Column and Place the Date
For TTR = 4 To lastcell 'Skip the header and move to last row only on the XX50Z obs
For TTR2 = bottom To 8515
bottom = 1
If Round(Sheets("OBS AT XX50Z").Range("H" & TTR2).Value, 5) = Round(Sheets("Difference").Range("F" & TTR2), 5) Then
Sheets("Difference").Range("I" & TTR).Value = Sheets("OBS AT XX50Z").Range("M" & TTR2).Value
Sheets("Difference").Range("J" & TTR).Value = Sheets("Difference").Range("I" & TTR).Value * 0.51444
Sheets("Difference").Range("K" & TTR).Value = Sheets("Difference").Range("G" & TTR).Value - Sheets("Difference").Range("J" & TTR).Value
End If
Next TTR2
counter = counter + 1
Sheets("Difference").Range("L4").Value = (counter) / (12500)
Next TTR
'
End Sub
[/CODE]

TylerTCF

Thanks for the help. So many tools I didn't know existed...out of curiosity what is the istringstream? Thanks for recommending vector...I will like using that way more than the old school hard numbered array...

TylerTCF

Sadly I have only C++ available to me...After using other languages, I'm mad about how difficult file i-o is with C++, but I don't remember it being too difficult...any help would be appreciated...

TylerTCF Light Poster

Need a recommendation on how to proceed with this task...I am starting new in C++ (after taking it in high school 11 years ago it has been forgotten and has changed alot). I have put the code I have below and some sample lines of data...any recommendations on how to load my array of weather observations would be appreciated. You will find that data is separated by a space and line breaks between observations. I only need the first several lines to remain individual and the rest of the observation I want to store as a string 'otherstuff'...is this even possible to do? I was having trouble with the getline working (which I know from reading is a common mistake). Help would be appreciated...

Attached below 1) Code to present 2) Sample Text

[CODE]

include
include
include
include

using namespace std; // put standard names into default namespace

//Struct Weather to decode obs in txt file to individual components
struct Weather {
int years;
int months;
int days;
int hours;
int windr;
int windsp;
int gust;
int waveht;
int waveperiod;
string otherstuff();
};

void main() {

string stuff;
int counter = 0;
Weather Later[75000];

/I have 75000 weather observations to decode and I want the structure to easily check each parameter against limitations I have using If-Then nested in a For-Loop (or While)/

ifstream DataFile("2007.txt");
while(!DataFile.eof()) {
getline(DataFile, stuff, ' ');
// This is where I want to distribute the paramters to the struct
counter++;
cin.get();
} ...